发个最底层代码:
int x;
Scanner input = new Scanner(System.in);
System.out.println("欢迎进入二进制转十进制系统\n请输入一个数:");
int num = input.nextInt();
int[] ten = new int[1000];
int[] two = new int[1000];
two[0]=1;
int b=1;
int sum=0;
for (x = 0; x < 1000; x++) {
ten[x] = num % 10;
num = num / 10;
if (num < 1) {
break;
}
}
for(int i=1;i<1000;i++){
two[i]=b*2;
b*=2;
}
for(int i=0,j=0;i<x+1;i++,j++){
sum+=ten[i]*two[j];
}
System.out.println(sum);