Repository navigation
Expand file tree
/
Copy pathSwitchCalc.java
More file actions
52 lines (39 loc) · 1.42 KB
/
Copy pathSwitchCalc.java
File metadata and controls
52 lines (39 loc) · 1.42 KB
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
import java.util.Scanner;
class SwitchCalc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calculator calc = new Calculator();
System.out.println("MENU");
System.out.println("1. Addition");
System.out.println("2. Substraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
System.out.print("Enter the first number: ");
int x = sc.nextInt();
System.out.print("Enter the second number: ");
int y = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Addition = " + calc.add(x,y));
break;
case 2:
System.out.println("Substraction = " + calc.sub(x,y));
break;
case 3:
System.out.println("Multiply = " + calc.multiply(x,y));
break;
case 4:
System.out.println("Division = " + calc.divide(x,y));
break;
case 5:
System.out.println("Exited Successfully!!");
break;
default:
System.out.println("Invalid Choice!");
break;
}
}
}