-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.java
31 lines (29 loc) · 910 Bytes
/
calculator.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
import java.util.*;
public class calculator {
public static void main(String args[]){
try(Scanner sc = new Scanner(System.in)){
System.out.println("Enter the value of a");
int a = sc.nextInt();
System.out.println("Enter the value of b");
int b = sc.nextInt();
System.out.println("Enter the operator");
char op = sc.next().charAt(0);
switch(op){
case '+' :
System.out.println(a+b);
break;
case '-' :
System.out.println(a-b);
break;
case '*' :
System.out.println(a*b);
break;
case '%' :
System.out.println(a%b);
break;
default :
System.out.println(a+b);
}
}
}
}