title: Checking user input to make sure each int is a number in Java
body: <p>I am writing a program that will ask the user to enter in 10 numbers separated by spaces and then displays the distinct numbers. My problem is coming in if a user enters in anything other than a number the program crashes. I am trying to use a has next checker but I am not sure how to get it to check all 10 numbers before sending them to my array. Here is my code any advice would be appreciated.</p>
  
  <pre><code>    import java.util.Scanner;
  
  
  public class DistinctNumbers 
  {
      static double input;
      static int number;
  
     public static void main(String[] args) 
     {
        char cont='N';
  
         do{
             menue();
  
             menueCatch();
  
             cont=contOption();
  
  
           }while(cont=='Y');
     }
  
      private static void menue()
          {
              System.out.print("Please make a selection."
                                 +"\n1: Begin"
                                 +"\n2: Exit"
                                 +"\n");
          }
  
      private static void menueCatch()
          {   
              Scanner userIn= new Scanner(System.in);
              int userChoice=userIn.nextInt();
  
              String input="";
  
              switch(userChoice)
              {
  
                  case 1:
                  {
                   process();
                   break;
                  }
  
                  case 2:
                  {
  
                   break;
                  }
              }
          }
  
      private static void process()
      {
        Scanner userIn = new Scanner(System.in);
          int[] numbers = new int[10];
          int count = 0;
  
  
          do 
              {
  
                  System.out.print("Enter ten numbers with a space seperating each number: ");
                  while (!userIn.hasNextInt()) 
                  {
                      System.out.println("That's not a number!");
                      System.out.println("Re-enter a number: ");
                      userIn.next();
                  }
                  number = userIn.nextInt();
              } while (number &lt; );
  
          for (int index = 0; index &lt; numbers.length; index++) 
          {
              int num = userIn.nextInt();
  
              if (isNew(numbers, num)) 
              {
                  numbers[count++] = num;
              }
          }
          System.out.println("The number of distinct number is " + count);
          System.out.print("The distinct numbers are: ");
          for (int index = 0; index &lt; count; index++) {
              System.out.print(numbers[index] + " ");
          }
      }
  
      private static boolean isNew(int[] numbers, int num) {
  
          for (int index : numbers){
              if (num == index) return false;
          }
          return true;
      }
  
       private static char contOption()
          {
              char answer;
          Scanner userIn=new Scanner(System.in);
          System.out.print("\nDo you wish to enter another 10 numbers?(Y/N): ");
          answer=userIn.next().toUpperCase().charAt(0);
  
          return answer;
          }    
  
  
  
  
  
  
  }
  </code></pre>