title: Calculator Try and Catch Java Program
body: <p>I'm trying to make a try/catch program calculator that removes the following errors but it isn't working. Please tell me what I'm doing wrong. I'm supposed to test for illegal operand operations and division by zero. </p>
  
  <pre><code>do // do while is for many operations
  {
      try
      {
          System.out.println("Enter num1 and num2 : ");
          int num1 = new Scanner();
          int num2 = new Scanner();
          System.out.println("Enter sign : ");
          char sign = new Scanner();
      }
      catch(IllegalArgumentException ex) // This will check for illegal inputs
      {
          System.out.println(ex.Message()); //Will print error message
      }
  
      if(sign == '+')
      { // part of code where you will write the plus operation
          System.out.println(num1+num2);
      }
      if(sign == '-')
      {
          System.out.println(num1-num2);
      }
      if(sign == '*')
      {
          System.out.println(num1*num2);
      }
      if(sign == '/')
      {
          try
          {
              System.out.println(num1/num2);
          }
          catch(ArithmeticException ex)// Check for divide by zero exception
          {
              System.out.println("Divide by zero");
          }
      }
  
      if(sign == 'x') // to exit
      {
          flag = false
      }
  
      else
      {
          System.out.println("Error : Unknown Operator\n");
      }
  
  }while(flag == true) // flag will be true until user enters 'x' as the choice to exit.
  </code></pre>