JAVA实现蓝桥杯基础练习十六进制转换八进制-----------拓展进制转换计算器
这个题目我浏览了大量的道友的文章发现十分麻烦,但仍然从其中收益菲薄,所以在这里分享一下我认为最好的代码
import java.math.BigInteger;
import java.util.Scanner;
public class L2021java_prictise {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
BigInteger []a = new BigInteger[n];
for (int i = 0;i < n;i++){
a[i] = new BigInteger(scanner.next(),16);
}
for(int j = 0;j < n;j++){
System.out.print(a[j].toString(8)+"\n");
}
}
}
进阶版本的任意进制转换计算器:
import java.math.BigInteger;
import java.util.Scanner;
public class L2021java_prictise {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入被转换数个数:"+"\n");
int n = scanner.nextInt();
System.out.print("请输入被转换数进制数:"+"\n");
int m = scanner.nextInt();
System.out.print("请输入将要转为____进制?:"+"\n");
int t = scanner.nextInt();
System.out.print("请输入你要转换的数字以回车分隔:"+"\n");
BigInteger []a = new BigInteger[n];
for (int i = 0;i < n;i++){
a[i] = new BigInteger(scanner.next(),m);
}
for(int j = 0;j < n;j++){
System.out.print(a[j].toString(t)+"\n");
}
}
}
希望对大家有所帮助,求赞!!!!