Java - Programming Language
This course covers the basics of programming in Java. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!

Better Calculator

Lesson 17
Author : GOUP
Last Updated : September, 2020


Code

Copy// 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);