-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathCalculator.java
37 lines (34 loc) · 1.22 KB
/
Calculator.java
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
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double value;
System.out.print("Please select the operator(+,-,*,/) : ");
char operator1 = sc.next().charAt(0);
System.out.print("Enter number 1 : ");
double num1 = sc.nextDouble();
System.out.print("Enter number 2 : ");
double num2 = sc.nextDouble();
switch (operator1){
case '+':
value = num1+num2;
System.out.println("num1 + num2 value is " + value);
break;
case '-':
value = num1-num2;
System.out.println("num1 - num2 value is " + value);
break;
case '*':
value = num1*num2;
System.out.println("num1 * num2 value is " + value);
break;
case '/':
value = num1/num2;
System.out.println("num1 / num2 value is " + value);
break;
default:
System.out.println("Invalid input! Please try again.");
break;
}
}
}