From c50b1f77958166480d6628af82b42edd7b55c48c Mon Sep 17 00:00:00 2001 From: xiexiaohang <1815965264@qq.com> Date: Thu, 10 Oct 2024 14:42:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=88=B6=E8=BD=AC=E6=8D=A2=EF=BC=88?= =?UTF-8?q?=E8=B0=A2=E6=BD=87=E8=88=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 ++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 9 ++++++ .idea/vcs.xml | 6 ++++ 1010Lession/1010Lession.iml | 11 +++++++ 1010Lession/src/jzzh/BaseConverter.java | 41 +++++++++++++++++++++++++ gitCode.iml | 11 +++++++ 7 files changed, 87 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 1010Lession/1010Lession.iml create mode 100644 1010Lession/src/jzzh/BaseConverter.java create mode 100644 gitCode.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /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..b0ef4c1 --- /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..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/1010Lession/1010Lession.iml b/1010Lession/1010Lession.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/1010Lession/1010Lession.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/1010Lession/src/jzzh/BaseConverter.java b/1010Lession/src/jzzh/BaseConverter.java new file mode 100644 index 0000000..b207961 --- /dev/null +++ b/1010Lession/src/jzzh/BaseConverter.java @@ -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); + } +} + diff --git a/gitCode.iml b/gitCode.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/gitCode.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file