-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCalculatorSwitch.java
More file actions
50 lines (49 loc) · 1.8 KB
/
Copy pathSimpleCalculatorSwitch.java
File metadata and controls
50 lines (49 loc) · 1.8 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
import java.util.Scanner;
public class SimpleCalculatorSwitch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("""
Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
Choice a function: \s""");
int option = sc.nextInt();
switch (option) {
case 1 -> {
System.out.println("Enter the first value: ");
int a = sc.nextInt();
System.out.println("Enter the second value: ");
int b = sc.nextInt();
int sum = a + b;
System.out.println("Addition: " + sum);
}
case 2 -> {
System.out.println("Enter the first value: ");
int a = sc.nextInt();
System.out.println("Enter the second value: ");
int b = sc.nextInt();
int sub = a - b;
System.out.println("Subtraction: " + sub);
}
case 3 -> {
System.out.println("Enter the first value: ");
int a = sc.nextInt();
System.out.println("Enter the second value: ");
int b = sc.nextInt();
int mul = a * b;
System.out.println("Multiplication: " + mul);
}
case 4 -> {
System.out.println("Enter the first value: ");
int a = sc.nextInt();
System.out.println("Enter the second value: ");
int b = sc.nextInt();
int div = a / b;
System.out.println("Division: " + div);
}
default -> System.out.println("Invalid option");
}
}
}