commit
c50b1f7795
@ -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,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/1010Lession/1010Lession.iml" filepath="$PROJECT_DIR$/1010Lession/1010Lession.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/gitCode.iml" filepath="$PROJECT_DIR$/gitCode.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>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,41 @@
|
||||
package jzzh;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BaseConverter {
|
||||
// 将任意 R 进制的数转换为十进制
|
||||
public static int convertToDecimal(String number, int base) {
|
||||
return Integer.parseInt(number, base);
|
||||
}
|
||||
|
||||
// 将十进制数转换为任意目标进制
|
||||
public static String convertFromDecimal(int decimalNumber, int targetBase) {
|
||||
return Integer.toString(decimalNumber, targetBase).toUpperCase(); // 使用大写表示结果
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// 输入原始进制
|
||||
System.out.print("请输入原始进制 (2 ≤ R ≤ 16): ");
|
||||
int originalBase = scanner.nextInt();
|
||||
|
||||
// 输入需要转换的数
|
||||
System.out.print("请输入进制数: ");
|
||||
String number = scanner.next().toUpperCase(); // 防止字母大小写混淆
|
||||
|
||||
// 输入目标进制
|
||||
System.out.print("请输入目标进制 (2 ≤ R ≤ 16): ");
|
||||
int targetBase = scanner.nextInt();
|
||||
|
||||
// 将原始 R 进制数转换为十进制
|
||||
int decimalNumber = convertToDecimal(number, originalBase);
|
||||
|
||||
// 将十进制数转换为目标 R' 进制
|
||||
String result = convertFromDecimal(decimalNumber, targetBase);
|
||||
|
||||
// 输出结果
|
||||
System.out.println("转换后的结果: " + result);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in new issue