title: How to reject inputs that are non digit characters?
body: <p>My professor assigned to write a prime number "finder". Where the number you input will display if it's a prime or even number, then display the next prime number. He wants us to give an error message when the wrong input is keyed in. I figured the negative integer portion is simple, but I cannot figure out the character input. Or if the character is not a digit. How would i block non numeric inputs?</p>
  
  <p>Also, the system is supposed to exit at three CONSECUTIVE erroneous inputs. How would I reset the counter? The way i have written the program, if the user makes two errors but the next ones are acceptable, then make another error. (thus not being consecutive.) the program closes.
  This is my first programing course so I'm not to savvy in it. Any help would be greatly appreciated.</p>
  
  <p>Also, i have to use scanner, and the two methods.</p>
  
  <pre><code>/**
   *
   * @param n
   * @return
   */
  public static boolean isPrime(int n) {
  
      for (int i = 2; i &lt; n; i++) {
          if (n % i == 0) {
              return false;
          }
      }
  
      return true;
  }
  
  
  
  public static int nextPrime(int n) {
      n++;
      isPrime(n);
      while (isPrime(n) == false) {
          n++;
          isPrime(n);
      }
      int prime = n;
      return prime;
  }
  
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      // TODO code application logic here
  
      int answer = 2;
      int counter = 1;
  
      boolean playAgain = false;
  
      Scanner input = new Scanner(System.in);
  
      Scanner reader = new Scanner(System.in);
  
      Scanner in = new Scanner(System.in);
  
      do {
          //ask for input
          System.out.print("\nEnter the integer value-&gt; ");
  
          //input answer
          int n = input.nextInt();
  
          {
             //decide is negative
              while ( n &lt; 0){
                  //count counter
                  counter++;
                  //give error message
                  System.out.println("\nInvalid Input! Stike!");
  
                //ask for input
                System.out.print("\nEnter the integer value-&gt; ");
  
                   //input answer
                   n = input.nextInt();
  
  
              //decide is character
             // if ( n != '.'){
                  //count counter
                 // counter++;
  
                  //give error message
                //  System.out.println("\nInvalid Input! Strike!");
             // }
  
              //decide if count three errors
              if (counter == 3){
  
              //display three errors message
              System.out.println("Three Strikes! You're Out!");
              //close program
              System.exit(0);
          }
              }
  
          //decide if prime
          if (isPrime(n)) {
  
              //display prime answer
              System.out.println(n + " Is Prime");
  
              //decide if even
          } else {
  
              //display even answer
              System.out.println(n + " Is Even");
  
          }
  
          //counter input
          n++;
  
          //while input is false
          while (isPrime(n) == false) {
              n++;
          }
  
  
          //display next prime
          System.out.println(n + " Next prime");
  
          {
  
              //ask if you want to continue
              System.out.println("\nPlay Again?\n\nEnter 1)Yes or 2)No ");
              //input answer
              answer = in.nextInt();
  
  
              //if answer is 1)yes
              if (answer == 1) {
                  playAgain = true;
  
                  //display play again and next input
                  System.out.println("\nPlay Again!");
              }
              //if answer is no
              if (answer == 2) {
                  playAgain = false;
                  System.out.println("\nGoodbye!");
                  //close program
                  System.exit(0);
              }
  
  
          }
  
          }
  
      } while (playAgain != false);
  }
  </code></pre>
  
  <p>}</p>