-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
42 lines (40 loc) · 1.01 KB
/
Copy pathCalculator.java
File metadata and controls
42 lines (40 loc) · 1.01 KB
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
import java.util.*;
public class Calculator {
public static void main(String args[]){
int a,b;
char c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number :");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("\n Enter operator");
c=sc.next().charAt(0);
switch(c){
case '+':System.out.println(a+b);
break;
case '-':if(a>b){
System.out.println(a-b);
} else{
System.out.println(b-a);
}
break;
case '*':System.out.println(a*b);
break;
case '/':if(b==0){
System.out.println("invalied intput of b");
}
else{
System.out.println(a/b);
}
break;
case '%':if(b==0){
System.out.println("invailed input of b");
}
else{
System.out.println(a%b);
}
break;
default:System.out.println("invailed input");
}
}
}