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(); + } +}