-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram68.java
More file actions
48 lines (42 loc) · 1.52 KB
/
Program68.java
File metadata and controls
48 lines (42 loc) · 1.52 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
import java.util.Scanner;
class SimpleCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the first number: ");
double num1 = input.nextDouble();
System.out.print("Enter the second number: ");
double num2 = input.nextDouble();
System.out.println("Choose an operation:");
System.out.println("1. Addition (+)");
System.out.println("2. Subtraction (-)");
System.out.println("3. Multiplication (*)");
System.out.println("4. Division (/)");
System.out.print("Enter the operation number: ");
int operation = input.nextInt();
double result;
switch (operation) {
case 1:
result = num1 + num2;
System.out.println("Result: " + result);
break;
case 2:
result = num1 - num2;
System.out.println("Result: " + result);
break;
case 3:
result = num1 * num2;
System.out.println("Result: " + result);
break;
case 4:
if (num2 != 0) {
result = num1 / num2;
System.out.println("Result: " + result);
} else {
System.out.println("Error: Division by zero is not allowed.");
}
break;
default:
System.out.println("Invalid operation.");
}
}
}