import java.util.Scanner;
class Test6 {
public static void main(String[] args) {
binToDex( );
}
private static void binToDex( ){
Scanner sc = new Scanner(System.in);
int temp = sc.nextInt() ;
String strTemp = temp+"" ;
int len = strTemp.length() ;
int result = 0 ;
String[]str = new String[len];
int [] arr = new int[len ];
int i = 0;
for( i = 0 ; i <len ; i++){
str = strTemp.charAt(i)+"";
}
for(int j = 0; j<str.length ; j++){
arr[j] = Integer.valueOf(str[j]);
}
for ( int k = 0 ; k <arr.length ; k++){
result += arr[k]*((int)Math.pow(2, len-1));
len--;
}
System.out.println(result);
}
}
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 = Integer.parseInt(line.charAt(i) + "");
}
int result = 0;
int len = arr.length;
for (int i = 0; i < arr.length; i++) {
result += arr * Math.pow(2, len - 1);
len--;
}
System.out.println(result);
}
华阿图 发表于 2016-11-26 13:09
帮你整理了一下代码:
[mw_shl_code=java,true]public static void main(String[] args) {
Scanner sc = n ...
dos.png (3.29 KB, 下载次数: 25)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |