-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
22 lines (22 loc) · 781 Bytes
/
Calculator.java
File metadata and controls
22 lines (22 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Calculator {
public static void main(String args[]){
if(args.length > 3){
System.out.println("Please,Check the Syntax");
System.exit(0);
}
int number1 = Integer.parseInt(args[0]);
int number2 = Integer.parseInt(args[2]);
switch(args[1].charAt(0)){
case '+' :
System.out.println(args[0] + " + " + args[2] +" = " + (number1 + number2)); break;
case '-' :
System.out.println(args[0] + " - " + args[2] + " = " + (number1 - number2)); break;
case '*' :
System.out.println(args[0] + " + " + args[2] + " = " + (number1 * number2)); break ;
case '/' :
System.out.println(args[0] + " + " + args[2] + " = " + (number1 / number2)); break ;
default :
System.out.println("Syntax error");
}
}
}