主方法,用于测试

main
今日不开张 2 months ago
parent 49fe5bf95b
commit 655bd0493a

@ -55,4 +55,27 @@ public class BaseConverter {
int decimalValue = toDecimal(str, sourceBase); int decimalValue = toDecimal(str, sourceBase);
return fromDecimal(decimalValue, targetBase); return fromDecimal(decimalValue, targetBase);
} }
/**
*
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 获取用户输入
System.out.print("请输入数据(例如 A1: ");
String input = scanner.nextLine().toUpperCase();
System.out.print("请输入源进制数(例如 16: ");
int sourceBase = scanner.nextInt();
System.out.print("请输入目标进制数(例如 2: ");
int targetBase = scanner.nextInt();
// 进制转换
String result = convertBase(input, sourceBase, targetBase);
System.out.println("转换结果:" + result); // 输出转换结果
scanner.close();
}
} }
Loading…
Cancel
Save