-
Notifications
You must be signed in to change notification settings - Fork 0
/
BASICS22.java
48 lines (42 loc) · 1.68 KB
/
BASICS22.java
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
import java.util.Scanner;
public class BASICS22 {
public static void main(String[] args) {
//CALCULATOR
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number-");
int a = sc.nextInt();
System.out.println("Enter the second number-");
int b = sc.nextInt();
System.out.println("Enter the operator(+,-,*,/,%)");
char operator = sc.next().charAt(0);
// switch (operator) {
// case '+':
// System.out.println("The sum of two number is: "+(a+b));
// case '-':
// System.out.println("The Difference of two number is: "+(a-b));
// case '*':
// System.out.println("The Multiplication of two number is: "+(a*b));
// case '/':
// System.out.println("The divison of two number is: "+(a/b));
// case '%':
// System.out.println("The remainder of two number is: "+(a%b));
// default:
// throw new AssertionError("INVALID OPERATOR");
// }
String result = switch (operator) {
case '+':
yield "The sum of two numbers is: " + (a + b);
case '-':
yield "The difference of two numbers is: " + (a - b);
case '*':
yield "The multiplication of two numbers is: " + (a * b);
case '/':
yield "The division of two numbers is: " + (a / b);
case '%':
yield "The remainder of two numbers is: " + (a % b);
default:
yield "Invalid operator!";
};
System.out.println(result);
}
}