forked from DeltechJavaAcademy/CLI-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.java
More file actions
61 lines (38 loc) · 1.16 KB
/
operations.java
File metadata and controls
61 lines (38 loc) · 1.16 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
61
package part1;
import java.util.Scanner;
public class operations {
public static void main(String[] args) {
System.out.println("Welcome to the CLI Calculator");
System.out.println("1. Addition" + '\n' + "2. Subtraction" + '\n' +
"3. Multiplication" + '\n' + "4. Division");
System.out.println("Choose your operation: ");
Scanner input = new Scanner(System.in);
int operation = input.nextInt();
System.out.println("First Number : ");
double a = input.nextDouble();
System.out.println("Second Number : ");
double b = input.nextDouble();
double result = 0;
switch(operation) {
case 1:
result = a + b;
System.out.println("Result of " + a + " + " + b + " = " + result);
break;
case 2:
result = a - b;
System.out.println("Result of " + a + " - " + b + " = " + result);
break;
case 3:
result = a * b;
System.out.println("Result of " + a + " * " + b + " = " + result);
break;
case 4:
if(b == 0) System.out.println("Cannot divide by 0");
else {
result = a / b;
System.out.println("Result of " + a + " / " + b + " = " + result);
}
break;
}
}
}