{
public static void main(String[] args) {
java.util.Scanner s=new java.util.Scanner(System.in);
System.out.println(“欢迎使用简单计算器系统”);
System.out.println(“请输入第一个数字”);
int num1 =s.nextInt();
System.out.println(“请输入运算符”);
String operator=s.next();
System.out.println(“请输入第二个数字”);
int num2 =s.nextInt();
int result=0;
switch(operator){
case “+”:
result=num1+num2;
break;
case “-”:
result=num1-num2;
break;
case “":
result=num1num2;
break;
case “%”:
result=num1%num2;
break;
case”/":
result=num1/num2;
break;
default:
System.out.println(“输入内容非法”);
}
System.out.println(num1+operator+num2+"="+result);
}
}
swtich 语句 简单计算器
最新推荐文章于 2024-03-28 22:17:36 发布