title: Java prevent users from entering anything except integers
body: <p>My intentions are to take a string input from a user, and only accept integer values. Maybe what I have is not the best approach to this and if that's the case let me know how I should go about changing my program. Lets say the user enters the values such as <code>1 2 3 4 a 5</code>. How do I go about preventing this little error. </p>
  
  <pre><code>String[] intVal;
  String inputValues;
  int[] numbers = new int[20];
  int count = 0;
  
  InputStreamReader reader = new InputStreamReader(System.in);
  BufferedReader input = new BufferedReader(reader);
  
  System.out.print("Enter up to 20 integer values here: ");
  inputValues = input.readLine();
  intVal = inputValues.split("\\s");
  
  for(int i = 0; i &lt; intVal.length; i++){
     numbers[i] = Integer.parseInt(intVal[i]);
     count++;
  }
  </code></pre>