/* Question 2 from lab 4 */ import java.util.Scanner; class CalculatorC { public static void main(String [] args){ Scanner console = new Scanner(System.in); int operand1,operand2; char operator; System.out.println("Enter two integers followed by one of the operators (+ - * /) OR cntl-z to quit"); while(console.hasNext()){ operand1 = console.nextInt(); operand2 = console.nextInt(); operator = console.next().charAt(0); switch(operator){ case '+' : System.out.println(operand1 + " + " + operand2 + " = " + (operand1 + operand2)); break; case '-' : System.out.println(operand1 + " - " + operand2 + " = " + (operand1 - operand2)); break; case '*' : System.out.println(operand1 + " * " + operand2 + " = " + (operand1 * operand2)); break; case '/' : if(operand2 !=0 ){ System.out.println(operand1 + " / " + operand2 + " = " + (operand1 / operand2)); }else{ System.out.println("Cannot divide by 0"); } default: System.out.println(operator + " Invalid Operator"); } System.out.println("Enter two integers followed by one of the operators (+ - * /), cntl-z to quit"); } } }