forked from Sonu2345/HactoberFest23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switch Case
45 lines (38 loc) · 1.34 KB
/
Switch Case
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 SwitchCase2 {
// Simple Calculator--
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your first number :");
int a = sc.nextInt();
System.out.println("Enter your second number :");
int b = sc.nextInt();
System.out.println("Which Operation you want to do :");
char op = sc.next().charAt(0);
switch (op) {
case '+':
System.out.printf("Addition of a and b is %d", a + b);
System.out.printf("\n");
break;
case '-':
System.out.printf("Subtraction of a and b is %d", a - b);
System.out.println("\n");
break;
case '*':
System.out.printf("Multiplication of a and b is %d", a * b);
System.out.printf("\n");
break;
case '/':
System.out.printf("Division of a and b is %d", a / b);
System.out.printf("\n");
break;
case '%':
System.out.printf("Mod is %d", a % b);
System.out.printf("\n");
break;
default:
System.out.println("Invalid Operator");
}
sc.close();
}
}