From 3ffc742dd5957c1c8307f3d1a60eb93415e9b469 Mon Sep 17 00:00:00 2001 From: yuan <3558860895@qq.com> Date: Thu, 10 Oct 2024 14:37:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=99=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 +++ .idea/ApifoxUploaderProjectSetting.xml | 6 ++ .idea/cyy_team.iml | 9 +++ .idea/encodings.xml | 6 ++ .idea/misc.xml | 6 ++ .idea/modules.xml | 9 +++ .idea/vcs.xml | 6 ++ demo/demo.iml | 11 ++++ demo/src/Main.java | 85 ++++++++++++++++++++++++++ 9 files changed, 146 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ApifoxUploaderProjectSetting.xml create mode 100644 .idea/cyy_team.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 demo/demo.iml create mode 100644 demo/src/Main.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ApifoxUploaderProjectSetting.xml b/.idea/ApifoxUploaderProjectSetting.xml new file mode 100644 index 0000000..a95a546 --- /dev/null +++ b/.idea/ApifoxUploaderProjectSetting.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/cyy_team.iml b/.idea/cyy_team.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/cyy_team.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8324963 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/demo/demo.iml b/demo/demo.iml new file mode 100644 index 0000000..6db0c46 --- /dev/null +++ b/demo/demo.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/demo/src/Main.java b/demo/src/Main.java new file mode 100644 index 0000000..26c6c22 --- /dev/null +++ b/demo/src/Main.java @@ -0,0 +1,85 @@ +import java.util.Scanner; + +public class Main { + + // 加法 + public static double add(double num1, double num2) { + return num1 + num2; + } + + // 减法 + public static double subtract(double num1, double num2) { + return num1 - num2; + } + + // 乘法 + public static double multiply(double num1, double num2) { + return num1 * num2; + } + + // 除法 + public static double divide(double num1, double num2) { + if (num2 == 0) { + System.out.println("错误: 除数不能为0"); + return Double.NaN; // 返回无效数字 + } + return num1 / num2; + } + + // 取余 + public static double remainder(double num1, double num2) { + if (num2 == 0) { + System.out.println("错误: 不能对0取余"); + return Double.NaN; // 返回无效数字 + } + return num1 % num2; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // 输入第一个数 + System.out.print("请输入第一个数: "); + double num1 = scanner.nextDouble(); + + // 输入运算符 + System.out.print("请输入运算符 (+, -, *, /, %): "); + char operator = scanner.next().charAt(0); + + // 输入第二个数 + System.out.print("请输入第二个数: "); + double num2 = scanner.nextDouble(); + + // 结果变量 + double result = 0; + + // 根据运算符选择操作 + switch (operator) { + case '+': + result = add(num1, num2); + break; + case '-': + result = subtract(num1, num2); + break; + case '*': + result = multiply(num1, num2); + break; + case '/': + result = divide(num1, num2); + break; + case '%': + result = remainder(num1, num2); + break; + default: + System.out.println("无效的运算符"); + return; + } + + // 输出结果 + if (!Double.isNaN(result)) { + System.out.println("结果: " + result); + } + + scanner.close(); + } +}