-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram6.java
More file actions
36 lines (33 loc) · 1.21 KB
/
Program6.java
File metadata and controls
36 lines (33 loc) · 1.21 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
// ------------ program to make a simple calculator using switch case ----------- //
import java.util.*;
public class Program6 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
float sum, diff, product, div;
System.out.println("enter the two numbers:");
float a = sc.nextFloat();
float b = sc.nextFloat();
System.out.println("enter the choice [ Addition - 1 | subtraction - 2 | multiplication - 3 | division - 4 ]");
int choice = sc.nextInt();
switch (choice) {
case 1:
sum = a + b;
System.out.println("The sum is: " + sum);
break;
case 2:
diff = a - b;
System.out.println("The difference is: " + diff);
break;
case 3:
product = a * b;
System.out.println("The product is: " + product);
break;
case 4:
div = a / b;
System.out.println("The division is: " + div);
break;
default:
System.out.println("Invalid choice");
}
}
}