public class Demo { public static void main (String[] arr) { if (arr.length < 3) { System.out.println("please input [java] [file] number1 [+-x/] number2"); System.exit(-1); } double number1 = Double.parseDouble(arr[0]); double number2 = Double.parseDouble(arr[2]); if (arr[1].equals("+")) { System.out.println(number1 + number2); } if (arr[1].equals("-")) { System.out.println(number1 - number2); } if (arr[1].equals("x")) {//命令行不可以输入"*"号,因为它有特殊含义,是通配符 System.out.println(number1 * number2); } if (arr[1].equals("/")) { if (number2 == 0) { System.out.println("被除数不能为0"); } System.out.println(number1 / number2); } } }