题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
String str = scanner.nextLine();
System.out.println(baseChange(str));
}
}
private static int baseChange(String s){
int i = s.length()-1;
int res = 0;
int pow = 0;
while(i >= 2){
char c = s.charAt(i);
if(c >= 65){
res += (c-55) * Math.pow(16, pow);
}else{
res += (c-48) * Math.pow(16, pow);
}
i--;
pow++;
}
return res;
}
腾讯成长空间 5977人发布