title: DoWhile seems to require repetitive input.nextLine()?
body: <p>thank you for taking a look at my question.</p>
  <p>This is a Java file when executed, takes in a name of a student and corresponding grades and when you type nothing in for the name, it computes the average of all of the students' grades. What I'm slightly confused about is why we need the below for the doWhile to continue asking for input?</p>
  <pre><code>// Read in the newline before looping back
                  input.nextLine();
  </code></pre>
  <p>I realized if I comment out the above line, the doWhile runs once and does not take any input for newStudent and exits the loop but I feel like the line below should already take care of it within the doWhile?</p>
  <pre><code>newStudent = input.nextLine();
  </code></pre>
  <p>Below is the entire code snippet.</p>
  <pre><code>import java.util.HashMap;
  import java.util.Map;
  import java.util.Scanner;
  
  public class HashMapGradebook {
  
      public static void main(String[] args) {
  
          HashMap&lt;String, Double&gt; students = new HashMap&lt;&gt;();
          Scanner input = new Scanner(System.in);
          String newStudent;
  
          System.out.println(&quot;Enter your students (or ENTER to finish):&quot;);
  
          // Get student names and grades
          do {
  
              System.out.print(&quot;Student: &quot;);
              newStudent = input.nextLine();
  
              if (!newStudent.equals(&quot;&quot;)) {
                  System.out.print(&quot;Grade: &quot;);
                  Double newGrade = input.nextDouble();
                  students.put(newStudent, newGrade);
  
                  // Read in the newline before looping back
                  input.nextLine();
              }
  
          } while(!newStudent.equals(&quot;&quot;));
  
          // Print class roster
          System.out.println(&quot;\nClass roster:&quot;);
          double sum = 0.0;
  
          for (Map.Entry&lt;String, Double&gt; student : students.entrySet()) {
              System.out.println(student.getKey() + &quot; (&quot; + student.getValue() + &quot;)&quot;);
              sum += student.getValue();
          }
  
          double avg = sum / students.size();
          System.out.println(&quot;Average grade: &quot; + avg);
      }
  }
  </code></pre>