parent
eadbd6479c
commit
c260ad9301
@ -1,5 +1,107 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("hello ");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("欢迎使用简单计算器!");
|
||||
System.out.println("请选择操作:");
|
||||
System.out.println("1. 加法");
|
||||
System.out.println("2. 减法");
|
||||
System.out.println("3. 乘法");
|
||||
System.out.println("4. 除法");
|
||||
System.out.println("5. 取余");
|
||||
System.out.print("输入你的选择(1/2/3/4/5): ");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
performAddition(scanner);
|
||||
break;
|
||||
case 2:
|
||||
performSubtraction(scanner);
|
||||
break;
|
||||
case 3:
|
||||
performMultiplication(scanner);
|
||||
break;
|
||||
case 4:
|
||||
performDivision(scanner);
|
||||
break;
|
||||
case 5:
|
||||
performModulus(scanner);
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效选择,请重试。");
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
private static void performAddition(Scanner scanner) {
|
||||
System.out.print("输入第一个数字: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.print("输入第二个数字: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
double result = num1 + num2;
|
||||
|
||||
System.out.println("结果: " + result);
|
||||
}
|
||||
|
||||
private static void performSubtraction(Scanner scanner) {
|
||||
System.out.print("输入第一个数字: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.print("输入第二个数字: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
double result = num1 - num2;
|
||||
|
||||
System.out.println("结果: " + result);
|
||||
}
|
||||
|
||||
private static void performMultiplication(Scanner scanner) {
|
||||
System.out.print("输入第一个数字: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.print("输入第二个数字: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
double result = num1 * num2;
|
||||
|
||||
System.out.println("结果: " + result);
|
||||
}
|
||||
|
||||
private static void performDivision(Scanner scanner) {
|
||||
System.out.print("输入第一个数字: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.print("输入第二个数字: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
if (num2 == 0) {
|
||||
System.out.println("错误: 除数不能为零。");
|
||||
} else {
|
||||
double result = num1 / num2;
|
||||
System.out.println("结果: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
private static void performModulus(Scanner scanner) {
|
||||
System.out.print("输入第一个数字: ");
|
||||
int num1 = scanner.nextInt();
|
||||
|
||||
System.out.print("输入第二个数字: ");
|
||||
int num2 = scanner.nextInt();
|
||||
|
||||
if (num2 == 0) {
|
||||
System.out.println("错误: 除数不能为零。");
|
||||
} else {
|
||||
int result = num1 % num2;
|
||||
System.out.println("结果: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/jeidui1.iml" filepath="$PROJECT_DIR$/jeidui1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in new issue