title: Scanner and nextInt discard integer
body: <p>I am using Scanner for taking user input in java. when i use nextInt() and the user inputs "2 5", then the value "2" is assigned and 5 is thrown away. What if I want to display that such an input is an error?
  One solution that comes to my mind is that i can use nextString() instead of nextInt() and then work my way out. But can anybody suggest a better solution?</p>
  
  <p>i realized that it is not throwing away the integer after space, instead it is using it for the next input.</p>
  
  <pre><code>import java.util.Scanner;
  class Test{
  static Scanner in=new Scanner(System.in);
  static void trial(){
      int k=in.nextInt();
      System.out.println(k);
      System.out.println(k);
  }
  
  public static void main(String[] args){     
      int k=in.nextInt();
      System.out.println(k);
      System.out.println(k);
      trial();        
  }
  }
  </code></pre>