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