-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator2.java
More file actions
60 lines (45 loc) · 1.15 KB
/
Copy pathCalculator2.java
File metadata and controls
60 lines (45 loc) · 1.15 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
53
54
55
56
57
58
59
60
package Exercises;
import java.util.Scanner;
public class Calculator2 {
public static void main(String[] args) {
String op;
int x;
int y;
Scanner scanner = new Scanner(System.in);
System.out.print("Operation: ");
op = scanner.nextLine();
switch (op.toLowerCase()) {
case "addition":
System.out.print("Addend: ");
x = scanner.nextInt();
System.out.print("Addend: ");
y = scanner.nextInt();
System.out.println("Sum: " + (x + y));
break;
case "subtraction":
System.out.print("Minuend: ");
x = scanner.nextInt();
System.out.print("Subtrahend: ");
y = scanner.nextInt();
System.out.println("Difference: " + (x - y));
break;
case "multiplication":
System.out.print("Multiplicand: ");
x = scanner.nextInt();
System.out.print("Multiplier: ");
y = scanner.nextInt();
System.out.println("Product: " + (x * y));
break;
case "division":
System.out.print("Dividend: ");
x = scanner.nextInt();
System.out.print("Divisor: ");
y = scanner.nextInt();
System.out.println("Quotient: " + (x / y));
break;
default:
System.out.println("Invalid operation");
}
scanner.close();
}
}