-
Notifications
You must be signed in to change notification settings - Fork 340
/
Calculator.java
68 lines (61 loc) · 2.09 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package basics;
import java.util.Objects;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input First Number : ");
int x = sc.nextInt();
System.out.print("Input Second Number : ");
int y = sc.nextInt();
System.out.print(" Enter the Operator : ");
String res = sc.next();
// ___________________If_Else______________________
//
// if (Objects.equals(res, "+")){
// System.out.println(x+y);
// }
// else if (Objects.equals(res, "-")){
// System.out.println(x-y);
// }
// else if (Objects.equals(res, "*")){
// System.out.println(x*y);
// }
// else if (Objects.equals(res,"/")){
// System.out.println(x/y);
// }
// else if (Objects.equals(res,"%")){
// System.out.println(x%y);
// }
// else {
// System.out.println("--------ERROR--------RORRE------------------------RORRE--------ERROR--------");
// }
// ___________________Normal_Switch_Case_________________
//
// switch (res) {
// case ("+"):
// System.out.println(x + y);
// break;
// case ("-"):
// System.out.println(x - y);
// break;
// case ("*"):
// System.out.println(x * y);
// break;
// case ("/"):
// System.out.println(x / y);
// break;
// case ("%"):
// System.out.println(x % y);
// break;
// }
// ____________________Enhanced_Switch_Case_______________________
switch (res) {
case "+" -> System.out.println(x + y);
case "-" -> System.out.println(x - y);
case "*" -> System.out.println(x * y);
case "/" -> System.out.println(x / y);
case "%" -> System.out.println(x % y);
}
}
}