-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment55.java
More file actions
70 lines (41 loc) · 1.73 KB
/
Assignment55.java
File metadata and controls
70 lines (41 loc) · 1.73 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package abhilash_Asignments;
//WAP to perform add,sub,multi,div using same 2 variables in switch case?
import java.util.Scanner;
//WAP to perform add,sub,multi,div using same 2 variables in switch case
public class Assignment55
{
public static void main(String[] args) //Main method
{
Scanner t1 = new Scanner(System.in); //scanner class is imported
System.out.print("Enter the first number: ");
double a1 = t1.nextDouble();
System.out.print("Enter the second number: ");
double a2 = t1.nextDouble();
// Input operation choice
System.out.println("select the option for opertion required : ");
System.out.println("Addition");
System.out.println("Subtraction");
System.out.println("Multiplication");
System.out.println("Division");
System.out.print("Enter your choice: ");
int choice = t1.nextInt();
// Perform the chosen operation
switch (choice) {
case 1:
System.out.println("Result: " + (a1 + a2));
break;
case 2:
System.out.println("Result: " + (a1 - a2));
break;
case 3:
System.out.println("Result: " + (a1 * a2));
break;
case 4:
System.out.println("Result: " + (a1/a2));
break;
default:
System.out.println("Invalid choice.");
break;
}
}
}