diff --git a/jinzhi.java b/jinzhi.java index c256b5c..41f7b5a 100644 --- a/jinzhi.java +++ b/jinzhi.java @@ -1,8 +1,8 @@ -import java.util.Scanner; +import javax.swing.JOptionPane; public class jinzhi { - // 将数字从 'fromBase' 转换为 'toBase' + // 将数字从 'fromBase' 转换为 'toBase'111 public static String convertBase(String number, int fromBase, int toBase) { // 第一步:从 'fromBase' 转换为十进制(base 10) int decimalNumber = 0; @@ -43,28 +43,24 @@ public class jinzhi { } public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - // 输入数字和基数 - System.out.print("请输入数字: "); - String number = scanner.nextLine(); - - System.out.print("请输入原始进制 (2 到 16): "); - int fromBase = scanner.nextInt(); - - System.out.print("请输入目标进制 (2 到 16): "); - int toBase = scanner.nextInt(); + String number = JOptionPane.showInputDialog("请输入数字:"); + String fromBaseInput = JOptionPane.showInputDialog("请输入原始进制 (2 到 16):"); + int fromBase = Integer.parseInt(fromBaseInput); + String toBaseInput = JOptionPane.showInputDialog("请输入目标进制 (2 到 16):"); + int toBase = Integer.parseInt(toBaseInput); // 验证基数 if (fromBase < 2 || fromBase > 16 || toBase < 2 || toBase > 16) { - System.out.println("基数必须在 2 到 16 之间。"); + JOptionPane.showMessageDialog(null, "基数必须在 2 到 16 之间。"); return; } // 转换数字并打印结果 String result = convertBase(number, fromBase, toBase); - System.out.println("进制为 " + fromBase + " 的数: " + number + " 在进制为 " + toBase + " 的数是: " + result ); + String message111 = "进制为 " + fromBase + " 的数: " + number + " 在进制为 " + toBase + " 的数是: " + result; - scanner.close(); + // 使用弹窗显示结果 + JOptionPane.showMessageDialog(null, message111); } }