package method;
import java.util.Scanner;
public class EnhancedTheCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double res = 0;
System.out.println("请输入第1个数字:");
double num1 = scanner.nextDouble();
System.out.println("请输入运算符:");
String cal =scanner.next();
System.out.println("请输入第二个数字:");
double num2 = scanner.nextDouble();
switch (cal) {
case "+":
res = num1 + num2;
break;
case "-":
res = num1 - num2;
break;
case "*":
res = num1 * num2;
break;
case "/":
if (num2 != 0) {
System.out.println("运算结果为:\n" + num1 + cal + num2 + "=" + res);
break;
} else {
System.out.println("结果不合法");
break;
}
default:
System.out.println("土鸡你的运算符不合法,请稍后重试");
return;
}
System.out.println("运算结果为:\n"+num1+cal+num2+"="+res);
scanner.close();
}
}
javaSE