You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
830 B
28 lines
830 B
import java.util.Scanner;
|
|
|
|
public class Transform4381 {
|
|
|
|
//此代码不实现界面
|
|
|
|
public static void main(String[] args) {
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
System.out.print("请输入输入数字: ");
|
|
String input = scanner.nextLine();
|
|
|
|
System.out.print("请输入从进制 (2, 8, 10, 16): ");
|
|
int fromBase = scanner.nextInt();
|
|
|
|
System.out.print("请输入到进制 (2, 8, 10, 16): ");
|
|
int toBase = scanner.nextInt();
|
|
|
|
try {
|
|
int number = Integer.parseInt(input, fromBase);
|
|
String result = Integer.toString(number, toBase);
|
|
System.out.println("转换结果: " + result);
|
|
} catch (NumberFormatException e) {
|
|
System.out.println("输入的数字在指定的进制中无效。");
|
|
}
|
|
}
|
|
}
|