题目
public class Main {
public static void main(String[] args) {
String str = "2021ABCD";
int k = 0;
long sum = 0;
for(int i=str.length()-1;i>=0;i--,k++) {
char c = str.charAt(i);
if(c>='A'&&c<='D') {
int res = c-'A'+10;
sum+=(long)res*Math.pow(16,k);
}else {
int res = c-'0';
sum+=(long)res*Math.pow(16, k);
}
}
System.out.println(sum);
}
}
public class Main {
public static void main(String[] args) {
String str = "2021ABCD";
int k = 0;
int sum = 0;
for(int i=str.length()-1;i>=0;i--,k++) {
char c = str.charAt(i);
if(c>='A'&&c<='D') {
int res = c-'A'+10;
sum+=res*Math.pow(16,k);
}else {
int res = c-'0';
sum+=res*Math.pow(16, k);
}
}
System.out.println(sum);
}
}
public class Main {
public static void main(String[] args) {
String s = "2021ABCD";
int sum = 0;
int j = 0;
for(int i=s.length()-1;i>=0;i--,j++) {
char c = s.charAt(i);
if(c>='A'&&c<='D') {
int sc = c-'A'+10;
sum += sc*Math.pow(16,j);
}else {
int sc = c-'0';
sum += sc*Math.pow(16,j);
}
}
System.out.println(sum);
}
}