1 public class Calculator {
2
3 public static void main(String[] args) {
4
5 if (args.length != 3) {
6 System.out.println(
7 "Usage: java Calculator operand1 operator operand2");
8 System.exit(1);
9 }
10
11
12 int result = 0;
13
14
15 switch (args[1].charAt(0)) {
16 case '+': result = Integer.parseInt(args[0]) +
17 Integer.parseInt(args[2]);
18 break;
19 case '-': result = Integer.parseInt(args[0]) -
20 Integer.parseInt(args[2]);
21 break;
22 case '.': result = Integer.parseInt(args[0]) *
23 Integer.parseInt(args[2]);
24 break;
25 case '/': result = Integer.parseInt(args[0]) /
26 Integer.parseInt(args[2]);
27 }
28
29
30 System.out.println(args[0] + ' ' + args[1] + ' ' + args[2]
31 + " = " + result);
32 }
33 }