-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator1.java
More file actions
58 lines (40 loc) · 1.21 KB
/
Copy pathCalculator1.java
File metadata and controls
58 lines (40 loc) · 1.21 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
package Exercises;
import java.util.Scanner;
public class Calculator1 {
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();
if (op.toLowerCase().equals("addition")) {
System.out.print("Addend: ");
x = scanner.nextInt();
System.out.print("Addend: ");
y = scanner.nextInt();
System.out.println("Sum: " + (x + y));
} else if (op.toLowerCase().equals("subtraction")) {
System.out.print("Minuend: ");
x = scanner.nextInt();
System.out.print("Subtrahend: ");
y = scanner.nextInt();
System.out.println("Difference: " + (x - y));
} else if (op.toLowerCase().equals("multiplication")) {
System.out.print("Multiplicand: ");
x = scanner.nextInt();
System.out.print("Multiplier: ");
y = scanner.nextInt();
System.out.println("Product: " + (x * y));
} else if (op.toLowerCase().equals("division")) {
System.out.print("Dividend: ");
x = scanner.nextInt();
System.out.print("Divisor: ");
y = scanner.nextInt();
System.out.println("Quotient: " + (x / y));
} else {
System.out.println("Invalid operation");
}
scanner.close();
}
}