public class SWITCH {
public static void main(String[] args) {
java.util.Scanner s = new java.util.Scanner(System.in);
int c;
System.out.print(“请输入第一个数字:”);
int a = s.nextInt();
System.out.print(“请输入第二个数字:”);
int b = s.nextInt();
System.out.print(“请输入运算符:”);
String oper = s.next();
switch (oper){
case “+”:
c = a+b;
System.out.print(“结果为:”+c);
break;
case “-”:
c = a-b;
System.out.print(“结果为:”+c);
break;
case "":
c = ab;
System.out.print(“结果为:”+c);
break;
case “/”:
c = a/b;
System.out.print(“结果为:”+c);
break;
}
}
}
SWITCH语句
最新推荐文章于 2025-03-30 19:12:53 发布