-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoWhileCalculus.java
More file actions
47 lines (35 loc) · 1.09 KB
/
doWhileCalculus.java
File metadata and controls
47 lines (35 loc) · 1.09 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
import java.util.Scanner;
public class doWhileCalculus {
public static void main(String[] args) {
char c = 0;
int num1;
int calc=0;
do {
Scanner userInput = new Scanner(System.in);
if (c=='y') {
System.out.println("First Number: " + calc);
num1 = calc;
}
else
{
System.out.println("Please enter the first number: ");
num1 = userInput.nextInt();
}
System.out.println("Please select operator: 0=='+', 1=='-', 2=='*', 3=='/'");
int opt = userInput.nextInt();
System.out.println("Please enter your second number: ");
int num2 = userInput.nextInt();
switch(opt) {
case(0): calc = num1+num2; break;
case(1): calc = num1-num2; break;
case(2): calc = num1*num2; break;
case(3): calc = num1/num2; break;
default : System.out.println("Wrong operator input"); break;
}
System.out.println(calc);
System.out.println("Would you like to continue? y/n");
c = userInput.next().charAt(0);
}while(c=='y');
System.out.println("Calculator is terminated!");
}
}