Compare commits
No commits in common. '33363a296aed1a16927df08cb0507cc551b94b0d' and '7397ef1c7ea2b68b13f970747bbef59454e9ac86' have entirely different histories.
33363a296a
...
7397ef1c7e
@ -1,3 +0,0 @@
|
|||||||
# 默认忽略的文件
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,11 +0,0 @@
|
|||||||
<?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$" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/jzq.iml" filepath="$PROJECT_DIR$/.idea/jzq.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,58 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class BaseConversion {
|
|
||||||
|
|
||||||
// 将任意R进制数转换为十进制数
|
|
||||||
public static int convertToDecimal(String numStr, int base) {
|
|
||||||
return Integer.parseInt(numStr, base);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将十进制数转换为任意R进制数
|
|
||||||
public static String convertFromDecimal(int num, int base) {
|
|
||||||
if (num == 0) {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
while (num > 0) {
|
|
||||||
int remainder = num % base;
|
|
||||||
if (remainder < 10) {
|
|
||||||
result.append(remainder);
|
|
||||||
} else {
|
|
||||||
result.append((char) ('A' + (remainder - 10))); // A-F 对应 10-15
|
|
||||||
}
|
|
||||||
num /= base;
|
|
||||||
}
|
|
||||||
return result.reverse().toString(); // 反转结果
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将一个R进制数转换为另一个R进制数
|
|
||||||
public static String convertBase(String numStr, int fromBase, int toBase) {
|
|
||||||
int decimalNumber = convertToDecimal(numStr, fromBase);
|
|
||||||
return convertFromDecimal(decimalNumber, toBase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.print("请输入要转换的数字: ");
|
|
||||||
String numStr = scanner.nextLine();
|
|
||||||
|
|
||||||
System.out.print("请输入源进制 (2-16): ");
|
|
||||||
int fromBase = scanner.nextInt();
|
|
||||||
|
|
||||||
System.out.print("请输入目标进制 (2-16): ");
|
|
||||||
int toBase = scanner.nextInt();
|
|
||||||
|
|
||||||
// 验证进制范围
|
|
||||||
if (fromBase < 2 || fromBase > 16 || toBase < 2 || toBase > 16) {
|
|
||||||
System.out.println("进制必须在 2 到 16 之间。");
|
|
||||||
} else {
|
|
||||||
String result = convertBase(numStr, fromBase, toBase);
|
|
||||||
System.out.println(numStr + " 从 " + fromBase + " 进制转换到 " + toBase + " 进制的结果是: " + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
//This is a test
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
# 默认忽略的文件
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,11 +0,0 @@
|
|||||||
<?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$" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/jzq.iml" filepath="$PROJECT_DIR$/.idea/jzq.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
# jzq
|
|
||||||
|
|
Loading…
Reference in new issue