title: how to avoid pressing several time enter affects the input data?
body: <p>I'm writting a JAVA Class to validate input data, especifically integer numbers. 
  The class I develop is running fine but when I press more than one time enter and then a char type, it display several times " Error!! Invalid number. Try again. " and I would like to avoid it.</p>
  
  <p>I have use nextLine() method but it doesn't seems to correct it. </p>
  
  <p>Here is the Class:</p>
  
  <pre><code>package chapter07.libro;
  
  import java.util.Scanner;
  
  public class Validator_integer 
  
  {
  
      public static int getInt (Scanner scanner, String promt)
  
      {
          int numberInteger = 0;
          boolean isValid = false;
  
          System.out.println(promt);
          while(isValid == false)
          {
              if(scanner.hasNextInt())
              {
                  numberInteger= scanner.nextInt();
                  isValid = true;
              }//if
  
              else
              {
                  System.out.println("Error!! Invalid number. Try again.");
              }//else
              scanner.nextLine();         
          }//while
  
          return numberInteger;   
      }//getInt
  
  }//Validator_integer
  </code></pre>
  
  <p>and next is the app to use the class:</p>
  
  <pre><code>package chapter.prueba;
  
  import java.util.Scanner;
  
  import chapter07.libro.Validator_integer;
  
  public class Test_Validator_Integer
  
  {
  
      public static void main(String[] args) {
  
          Scanner sc = new Scanner (System.in);
          String choice = "y";
  
          while(choice.equalsIgnoreCase("y"))
          {
              int number = Validator_integer.getInt(sc, "Enter integer number: ");
              System.out.println(number);
  
              System.out.println("Continue (y/n): ");
              choice = sc.next();
  
          }//while
  
      }//main
  
  }//Test_Validator_Integer
  </code></pre>
  
  <p>The results I get are next:</p>
  
  <pre><code>Enter integer number: 
  
  2
  
  2
  
  Continue (y/n): 
  
  y
  
  Enter integer number: 
  
  (Here I press several time enter)
  
  xx
  
  Error!! Invalid number. Try again.
  
  Error!! Invalid number. Try again.
  
  Error!! Invalid number. Try again.
  
  Error!! Invalid number. Try again.
  
  2
  
  2
  
  Continue (y/n): 
  
  n
  </code></pre>
  
  <p>So the part of (Error!! Invalid number. Try again.) displayed several times, is the one I would like to avoid.</p>
  
  <p>Does any one know how to fix it???
  Thanks in advance!!!</p>