title: Java Validating Input in a Basic Calculator Program
body: <p>I am looking for the answer to how do I make my program run correctly. I want my program to recognize things other than doubles--- for example, if i placed in <strong><em>idk</em></strong> it would say, <strong><em>that is not a number</em></strong> instead of crashing. </p>
  
  <p>my code: </p>
  
  <pre><code>import java.util.*;
  
  public class CalculatorMain {
      public static void main(String[] args) {
  
          FunctionMain action = new FunctionMain();
  
           Scanner input = new Scanner(System.in);
  
          double answer = 0;
          double inputNu1, inputNu2;
          char operator;
          boolean end = false;
  
       while (! end ) {
              System.out.print("&gt;&gt;&gt;");
  
              inputNu1 = input.nextDouble();
              operator = input.next().charAt(0);
              inputNu2 = input.nextDouble();        
  
      switch (operator) 
              {
          case '-': answer = action.Subtract(inputNu1, inputNu2);
                  break;
          case '*': answer = action.Multiply(inputNu1, inputNu2);
                  break;
          case '+': answer = action.Add(inputNu1, inputNu2);
                  break; 
          case '/': answer = action.Divide(inputNu1, inputNu2);
                 break;          
              }
  
          System.out.println(answer);             
          }       
          input.close();
  
      }
  
  }
  
  
  
  public class FunctionMain {
  
       double Subtract (double Nu1 , double Nu2)
      {
           return Nu1 + Nu2;
  
      }
      double Multiply (double Nu1 , double Nu2)
      {
          return Nu1 * Nu2;
      }
      double Add (double Nu1 , double Nu2)
  
      {
          return Nu1  + Nu2;
      }
      double Divide (double Nu1 , double Nu2)
  
      {  
          return Nu1 / Nu2;
      }
  
  }
  </code></pre>