帮你整理了一下代码:
[Java] 纯文本查看 复制代码 public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
int arr[] = new int[line.length()];
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(line.charAt(i) + "");
}
int result = 0;
int len = arr.length;
for (int i = 0; i < arr.length; i++) {
result += arr[i] * Math.pow(2, len - 1);
len--;
}
System.out.println(result);
} |