Better Calculator
Lesson 17Author : 🦒
Last Updated : October, 2017
Code
// import java.util.Scanner;
Scanner keyboardInput = new Scanner(System.in);
System.out.print("Enter num1: ");
int num1 = keyboardInput.nextDouble(); // .nextDouble(), .nextInt()
System.out.print("Enter Operator: ");
String op = keyboardInput.nextLine();
System.out.print("Enter num2: ");
int num2 = keyboardInput.nextDouble();
if(op.equals("+")){
System.out.println(num1 + num2);
} else if(op.equals("-")){
System.out.println(num1 - num2);
} else if(op.equals("/")){
System.out.println(num1 / num2);
} else if(op.equals("*")){
System.out.println(num1 * num2);
} else {
System.out.println("Invalid Operator");
}
System.out.println(num1 + num2);