-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoose.java
More file actions
52 lines (51 loc) · 1.83 KB
/
Choose.java
File metadata and controls
52 lines (51 loc) · 1.83 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
import java.util.Scanner;
import java.lang.Math;
//docker build -t java_choose_image .
//docker run -it --rm --name choose_container java_choose_image
public class Choose {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
boolean exit = false;
while(!exit) {
System.out.println("What would you like to do? 1 to add two integers, 2 to multiply two integers, 3 to subtract two integers, 4 to calculate one integer to the power of another, and 5 to exit.");
if(!input.hasNextInt()) {
System.out.println("Input one of 1, 2, 3, 4, 5.");
input.next();
continue;
}
int selection = input.nextInt();
if (selection == 5){
break;
}
if(selection < 1 || selection > 5){
System.out.println("Input one of 1, 2, 3, 4, 5.");
continue;
}
System.out.println("Input two integers");
while (!input.hasNextInt()) {
System.out.println("Input an integer.");
}
int int1 = input.nextInt();
while (!input.hasNextInt()) {
System.out.println("Input an integer.");
}
int int2 = input.nextInt();
int result = -1;
switch (selection) {
case 1:
result = int1 + int2;
break;
case 2:
result = int1 * int2;
break;
case 3:
result = int1 - int2;
break;
default:
result = (int) Math.pow((double)int1, (double)int2);
}
System.out.println("Result is: "+ result);
}
input.close();
}
}