From 9aaa5210e3c7bf30e3ddf212aa39ac28a6cbcbc7 Mon Sep 17 00:00:00 2001 From: dsc <3468364190@qq.com> Date: Wed, 9 Oct 2024 10:43:23 +0800 Subject: [PATCH] 1.2.1 --- Test/src/Computer.java | 61 +++++++++++++++++++++++++++++ out/production/Test/Computer.class | Bin 0 -> 2138 bytes 2 files changed, 61 insertions(+) create mode 100644 out/production/Test/Computer.class 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 0000000000000000000000000000000000000000..f8a89aa3e3bb4234105236d6dc341b0583429d06 GIT binary patch literal 2138 zcmah}TTB#J82--gGBZ02ARxG_g|4mOE*Dp^qTK97YN183U8|zK4a)$dd%@jVQr}G4 zCT&`uj3Kmr=tEmmLu2&;h>bq=sWIuJNgoY2lRh@-Tj_UZxhzQPZvJ!r|3Clv{_C0F z|GoDBz)Ns+1kt79s2?xm6&)VD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