## viewing paste ArithmeticCalculator | Java

Posted on the
Copied to clipboard
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ```//For the input in console to work import java.util.Scanner;   public   class   ArithmeticCalculator{        public   static   void  main(String[] args){       //define scan as scannner       Scanner scan = new Scanner(System.in);       //define operator as String       String operator = new String();             //Simple text display       System.out.print("Please indicate the first number in the equation: ");       //Using double for division       double num_1 = scan.nextInt();       System.out.print("Please indicate the operator: ");       operator = scan.next();       System.out.print("Please indicate the second number of the equation: ");       //using double for division       double num_2 = scan.nextInt();       System.out.println("Thank you.. now processing..");       System.out.println("Your first number was "+num_1+". Your second number was "+num_2+". Your operator was "+operator);             //Turn the string into a char       char op = operator.charAt(0);             //send program to correct step depending on operator       switch(op){          case '*':             System.out.println("Answer is: "+(num_1*num_2));             break;                    case '/':             System.out.println("Answer is: "+(num_1/num_2));             break;                    case '+':             System.out.println("Answer is: "+(num_1+num_2));             break;                    case '-':             System.out.println("Answer is: "+(num_1-num_2));             break;                    //If none of the above apply          default:                System.out.println("Invalid Operator");         //Stop application                System.exit(0);                   }           }     }```
Viewed 1213 times, submitted by Streusel.