-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator
73 lines (54 loc) · 1.45 KB
/
Calculator
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class calculator {
public static void main(String[] args) {
int n1, n2;
boolean b = true;
String operation;
while (b = true) {
Scanner scannerObject = new Scanner(System.in);
System.out.println("Please enter your first number:");
n1 = scannerObject.nextInt();
Scanner op = new Scanner(System.in);
System.out.println("Enter your operation");
operation = op.next();
System.out.println("Please enter your second number:");
n2 = scannerObject.nextInt();
switch (operation) {
case "+":
System.out.println("Your answer is " + (n1 + n2));
break;
case "-":
System.out.println("Your answer is " + (n1 - n2));
break;
case "/":
System.out.println("Your answer is " + (n1 / n2));
break;
case "*":
System.out.println("Your answer is " + (n1 * n2));
break;
case "%":
System.out.println("Your answer is " + (n1 % n2));
break;
default:
System.out.println("Incorrect Numbers!!! Please Try again...");
}
Scanner result = new Scanner(System.in);
System.out.println("Press q to quit,c to clear and start again or i to operate on result");
char i = result.next().charAt(0);
switch (i) {
case 'q':
b = false;
break;
case 'c':
b = true;
break;
case 'i':
System.out.println();
break;
default:
System.out.println("Something went wrong");
}
}
System.out.println("The system has been terminated");
}
}