title: java.util.Scanner: keeps waiting for additional input
body: <p>Total Java newbie here.  Working on one of my very first Java programs.  Please help.
  Here's what I am trying to achieve:
  I need to accept user keyboard input of whitespace separated integers, copy them into an array and process them. KNOWN: user will enter only ONE line of data. I don't know how many numbers, but once they hit Enter, there won't be any more. As user input may contain words and special characters, I need to handle them with neat errors and prompt user to try again. When I run what I wrote below, I get in some kind of infinite loop where Scanner keeps waiting for additional input. How do I tell it it's over and there won't be any more input? </p>
  
  <p>Here's the code:</p>
  
  <pre><code>&lt;!-- language-all: java --&gt;
  
  public static void EnterInts () {
  
      System.out.println("Enter series of integers separated by whitespace. Press Enter key when finished.");
      Scanner input = new Scanner(System.in);
      while (input.hasNext()){
          if (input.hasNextInt(){
              int i = input.nextInt();
              System.out.println(i);
          }
          else {
              System.out.println("Only integers can be entered. Try again.");
          }
      }
  }
  </code></pre>