title: Getting User input with Scanner
body: <p>I am trying to have a scanner take input in a loop. Once the user wants to finish he can exit this loop. I have tried many different ways to do it but there is always some problem. This is the code:</p>
  
  <pre><code>private void inputEntries() {
      Scanner sc = new Scanner(System.in);
      System.out.println("Continue?[Y/N]");
      while (sc.hasNext() &amp;&amp; (sc.nextLine().equalsIgnoreCase("y"))) {//change here
          System.out.println("Enter first name");
          String name = sc.nextLine();
          System.out.println("Enter surname");
          String surname = sc.nextLine();
          System.out.println("Enter number");
          int number = sc.nextInt();
          Student student = new Student(name, surname, number);
          students.add(student);
          try {
              addToFile(student);
          } catch (Exception ex) {
              Logger.getLogger(TextReader.class.getName()).log(Level.SEVERE, null, ex);
          }
          System.out.println("Continue?[Y/N]");
      }
  }
  </code></pre>
  
  <p>The problem with the code above, which also happens on different methods I tried, is that when the user types <em>Y</em>, the <code>Scanner</code> will skip the first input for first name,and jump to the surname. If the user types <em>N</em> the loop stops correctly. Someone can explain the reason this happens, and how to overcome using <code>Scanner</code> class?</p>
  
  <p>p.s: Doing something like <code>while(sc.nextLine().equals("Y"))</code>, will cause the loop to terminate before getting input from user after first run of the loop.</p>