forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitchExample1.java
More file actions
42 lines (37 loc) · 1.17 KB
/
SwitchExample1.java
File metadata and controls
42 lines (37 loc) · 1.17 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
package InfinityJune21.SwitchExamples;
import java.util.*;
public class SwitchExample1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("Enter the choice: ");
int choice = scanner.nextInt();
System.out.println("Enter first number: ");
int num1 = scanner.nextInt();
System.out.println("Enter second number: ");
int num2 = scanner.nextInt();
int result;
switch (choice) {
case 1:
result = num1 + num2;
break;
case 2:
result = num1 - num2;
break;
case 3:
result = num1 * num2;
break;
case 4:
result = num1 / num2;
break;
default:
result = 0;
break;
}
System.out.println("Result: " + result);
scanner.close();
}
}