-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcSwitch.java
More file actions
45 lines (32 loc) · 992 Bytes
/
CalcSwitch.java
File metadata and controls
45 lines (32 loc) · 992 Bytes
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
import java.util.Scanner;
public class CalcSwitch{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int ans,a,b,choice;
System.out.println("Enter a: ");
a = sc.nextInt();
System.out.println("Enter b: ");
b = sc.nextInt();
System.out.println("1 for Addition.");
System.out.println("2 for Subtraction.");
System.out.println("3 for Multiplication.");
System.out.println("4 for Divison.");
System.out.println("Enter Choice: ");
choice = sc.nextInt();
switch(choice){
case 1 : ans = a+b;
System.out.println("Addition: "+ans);
break;
case 2 : ans = a-b;
System.out.println("Subtraction: "+ans);
break;
case 3 : ans = a*b;
System.out.println("Multiplication: "+ans);
break;
case 4 : ans = a/b;
System.out.println("Divison: "+ans);
break;
default : System.out.println("Wrong Choice! Enter choice between 1 to 4");
}
}
}