尽量不要用==判断字符串
用equals
new中自动补全 ,ctrl+Alt+v
switch与case
case穿透,若没有break,下面的都会跑
public static void main(String【】 args) {
java.util.Scanner s = new java.util.Scanner(System.in);
System.out.print(“请输入第一个数字:”);
int num1 = s.nextInt();
System.out.print(“请输入运算符:”);
String operator = s.next();
System.out.print(“请输入第二个数字:”);
int num2 = s.nextInt();
int result = 0;
switch (operator){
case “+” :
result = num1 + num2;
break;
case “-” :
result = num1 - num2;
break;
case “*” :
result = num1 * num2;
break;
case “/” :
result = num1 / num2;
break;
case “%” :
result = num1 % num2;
break;
default:
System.out.println(“你的输入不合法!!!”);
}
s.close();
System.out.println(num1 + operator + num2 + “=” + result);