-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCalculator.java
More file actions
54 lines (53 loc) · 1.31 KB
/
Copy pathSimpleCalculator.java
File metadata and controls
54 lines (53 loc) · 1.31 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
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b;
System.out.println("Enter two numbers:");
a=sc.nextInt();
b=sc.nextInt();
int opt;
while(true){
System.out.println("1.Add 2.Subtract 3.Multiply 4.Division 5.Remainder 6.Try with other numbers 7.exit");
opt = sc.nextInt();
if(opt==7){
break;
}
else if(opt==1){
System.out.println(a+b);
}
else if(opt == 2){
System.out.println(a-b);
}
else if(opt == 3){
System.out.println(a*b);
}
else if(opt == 4){
try{
System.out.println(a/b);
}
catch(Exception e){
System.out.println("Number is not divisible by zero");
}
}
else if(opt ==5){
try{
System.out.println(a%b);
}
catch(Exception e){
System.out.println("Number is not divisible by zero");
}
}
else if(opt == 6){
System.out.println("enter two numbers:");
a = sc.nextInt();
b = sc.nextInt();
System.out.println("which operation should need to perform");
}
else{
System.out.println("INVALID OPERATOR");
}
}
}
}