public class Calculator {
public static void main(String[] args) {
System.out.println("欢迎使用简单的计算器!");
System.out.print("请输入第一个数字:");
java.util.Scanner s = new java.util.Scanner(System.in);
double num1 = s.nextDouble();
System.out.print("请输入运算符:");
String operator = s.next();
System.out.print("请输入第二个数字:");
double num2 = s.nextDouble();
double result = 0;
switch (operator) {
case "+":
result = num1 + num2;
break;
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);
}
}
Une simple calculatrice
Je suppose que tu aimes
Origine blog.csdn.net/THJYS/article/details/105215528
conseillé
Classement