题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int sum = 0;
for (int i = 0; i < s.length() - 2; i++) {
char c = s.charAt(i + 2);
int temp = 0;
if (c >= '0' && c <= '9')
temp = c - '0';
else if (c >= 'A' && c <= 'F')
temp = c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
temp = c - 'a' + 10;
sum += temp * Math.pow(16, s.length() - i - 3);
}
System.out.println(sum);
}
}
