// 利用Scanner 和 switch 写一个简易的 加减乘除 计算器;
public class Computer {
public static void main(String[] args) {
// 创建Scanner 扫描器接收用户的输入
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一数字:");
double a = scanner.nextDouble();
System.out.println("请输入运算符:");
String b = scanner.next();
System.out.println("请输入第二个数字:");
double c = scanner.nextDouble();
switch (b){
case "+":
double add = a+c;
System.out.println(a+"+"+c+"的结果为:"+add);
break;
case "-":
double sub = a-c;
System.out.println(a+"-"+c+"的结果为:"+sub);
break;
case "*":
double mul = a*c;
System.out.println(a+"*"+c+"的结果为:"+mul);
break;
case "/":
double dev = a/c;
System.out.println(a+"/"+c+"的结果为:"+dev);
break;
default:
System.out.println("请按要求输入运算符:+ - * /");
break;
}
scanner.close(); //关闭扫描器
}
}