import java.util.Scanner;
public class Calculator
{ public static void main(String[] args)
{ Scanner scanner = new Scanner(System.in);
System.out.println("欢迎使用简单计算器!");
System.out.print("请输入第一个操作数:");
double operand1 = scanner.nextDouble();
System.out.print("请输入第二个操作数:");
double operand2 = scanner.nextDouble();
System.out.print("请选择运算符(+、-、*、/):");
char operator = scanner.next().charAt(0);
double result = 0;
switch (operator) {
case '+':
result = operand1 + operand2;
break;
case '-':
result = operand1 - operand2;
break; case '*':
result = operand1 * operand2; break; case '/':
if (operand2 == 0) { System.out.println("除数不能为0,请重新输入。");
return;
} result = operand1 / operand2;
break;
default:
System.out.println("输入的运算符不合法,请重新输入。");
return;
}
System.out.println("运算结果为:" + result);
} }