-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
29 lines (28 loc) · 1.2 KB
/
main.java
File metadata and controls
29 lines (28 loc) · 1.2 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
public class Main { // Class name should start with an uppercase letter (Java convention)
public static void main(String[] args) {
int x = Integer.parseInt(args[0]); // Convert the first argument to an integer
int y = Integer.parseInt(args[1]); // Convert the second argument to an integer
String operation = args[2].toLowerCase(); // Convert the third argument (operation) to lowercase
switch (operation) {
case "add":
System.out.println("The sum of two numbers is " + (x + y));
break;
case "subtract":
System.out.println("The sub of two numbers is " + (x - y));
break;
case "multiply":
System.out.println("The mul of two numbers is " + (x * y));
break;
case "divide":
if (y != 0) {
System.out.println("The div of two numbers is " + (x / y));
} else {
System.out.println("Division by zero is not allowed.");
}
break;
default:
System.out.println("Invalid operation.");
break;
}
}
}