//import java.util.Scanner;
//import sun.tools.tree.Vset;
public class Switch0726{
public static void main(String[] args) {
java.util.Scanner s=new java.util.Scanner(System.in);
System.out.println("欢迎使用本计算器");
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;
}
System.out.println("你的运算结果是:" + num1 + operator + num2 + "=" + result);
}
}
实例2更加简洁
原文地址:https://www.cnblogs.com/zhuojinyong/p/11605633.html
时间: 2024-10-21 03:33:17