title: Testing for blank input using Scanner class during input validation
body: <p>I need to ask the user to enter a positive non-zero integer from the console that I will use as a product number in my program. </p>
  
  <p>If I enter any non-integer value, the program correctly enters the while loop.</p>
  
  <p>If I enter a 0 or a negative integer,  the program correctly throws the exception (which I catch and handle elsewhere).</p>
  
  <p>When I just press the enter key (or end of line character) it seems that the program just puts the console to another line. I want it to enter the while loop to display the error message. I think the cause is that <code>hasNextInt()</code> will wait until the token is a non end of line character input.</p>
  
  <pre><code>private static void validateProductNumber() throws InvalidProductNumberException { 
      Scanner keyboard = new Scanner(System.in);
      int number;
      while(!keyboard.hasNextInt()) { 
          System.out.println("Number must be an integer. Try again. ");
          System.out.println("Enter a new number: ");
          keyboard.next(); 
      }
      number = keyboard.nextInt();
      if (number &lt;= 0)
          throw new InvalidProductNumberException();
      newNumber = number;
  }
  </code></pre>
  
  <p>Is there another way I can implement my input validation with Scanner class so that it works correctly for all situations?</p>