-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator using do while loop
48 lines (46 loc) · 1.67 KB
/
calculator using do while loop
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
import java.util.*;
public class calculator {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int button,a,b;
do {
System.out.print(
"1 : + (Addition) a + b\n" +
"2 : - (Subtraction) a - b\n" +
"3 : * (Multiplication) a * b\n" +
"4 : / (Division) a / b\n" +
"5 : % (Modulo or remainder) a % b\n" +
"6 : Exit\n");
System.out.println("Enter your option(1..6): ");
button = sc.nextInt();
if(button==6){
System.out.println("Exit success..");
System.exit(0);
}
System.out.println("Enter your first number");
a = sc.nextInt();
System.out.println("Enter your second number");
b = sc.nextInt();
switch (button) {
case 1:
System.out.println("Output is a + b = "+a + b);
break;
case 2:
System.out.print("Output is a - b = ");
System.out.println(a - b);
break;
case 3:
System.out.println("Output is a * b = "+a * b);
break;
case 4:
System.out.println("Output is a / b = "+a / b);
break;
case 5:
System.out.println("Output is a % b = "+a % b);
break;
default:
System.out.println("Enter wrong button");
}
}while (button != 6);
}
}