diff --git a/Test/src/Computer.java b/Test/src/Computer.java index 2d6a943..5205d82 100644 --- a/Test/src/Computer.java +++ b/Test/src/Computer.java @@ -1,2 +1,63 @@ +import java.util.Scanner; + public class Computer { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("请输入第一个数字:"); + double num1 = scanner.nextDouble(); + + System.out.println("请输入第二个数字:"); + double num2 = scanner.nextDouble(); + + System.out.println("请选择操作 (+, -, *, /):"); + String operation = scanner.next(); + + double result; + switch (operation) { + case "+": + result = add(num1, num2); + break; + case "-": + result = subtract(num1, num2); + break; + case "*": + result = multiply(num1, num2); + break; + case "/": + if (num2 != 0) { + result = divide(num1, num2); + } else { + System.out.println("除数不能为零!"); + return; + } + break; + default: + System.out.println("无效的操作符!"); + return; + } + + System.out.printf("%.2f %s %.2f = %.2f\n", num1, operation, num2, result); + } + + // 加法 + public static double add(double a, double b) { + return a + b; + } + + // 减法 + public static double subtract(double a, double b) { + return a - b; + } + + // 乘法 + public static double multiply(double a, double b) { + return a * b; + } + + // 除法 + public static double divide(double a, double b) { + return a / b; + } } + diff --git a/out/production/Test/Computer.class b/out/production/Test/Computer.class new file mode 100644 index 0000000..f8a89aa Binary files /dev/null and b/out/production/Test/Computer.class differ