-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.java
60 lines (53 loc) · 1.4 KB
/
Calculator.java
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
import java.util.Scanner;
public class Calculator {
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
double a, b, total;
int choice;
do {
System.out.print("Enter an operation\n"
+ "1) Addition\n"
+ "2) Subtraction\n"
+ "3) Multiplication\n"
+ "4) Division\n"
+ "5) Exit\n"
+ ": ");
choice = kb.nextInt();
switch(choice) {
case 1:
System.out.print("Enter two values to add: ");
a = kb.nextDouble();
b = kb.nextDouble();
total = a + b;
System.out.println(a + " + " + b + " = " + total + ".\n");
break;
case 2:
System.out.print("Enter two values to subtract: ");
a = kb.nextDouble();
b = kb.nextDouble();
total = a - b;
System.out.println(a + " -" + b + " = " + total + ".\n");
break;
case 3:
System.out.print("Enter two values to multiply: ");
a = kb.nextDouble();
b = kb.nextDouble();
total = a * b;
System.out.println(a + " * " + b + " = " + total + ".\n");
break;
case 4:
System.out.print("Enter two values to divide: ");
a = kb.nextDouble();
b = kb.nextDouble();
total = a / b;
System.out.println(a + " / " + b + " = " + total + ".\n");
break;
case 5:
System.out.println("Shutting off.");
break;
default:
System.out.println("Please choose from the options below.\n");
}
}while(choice != 5);
}
}