牛课网上的题目
char '1'和 int 1给我好好上了一课
package suanfa; import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ String s = in.nextLine(); s = s.substring(2); int l = s.length(); char[] ch = s.toCharArray(); int sum = 0; int j = 1; int temp = 0; for(int i = l-1; i >= 0; i--){ if(ch[i] == 'A'){ temp = 10; } else if(ch[i] == 'B'){ temp = 11; } else if(ch[i] == 'C'){ temp = 12; } else if(ch[i] == 'D'){ temp = 13; } else if(ch[i] == 'E'){ temp = 14; } else if(ch[i] == 'F'){ temp = 15; } else{ temp = (int)ch[i] - (int)'0'; //一开始直接 temp = ch[i]得到的是ASCII码 } //System.out.println(ch[i]); //System.out.println(sum); //System.out.println(j); //System.out.println(temp); sum=sum + j*temp; j = j*16; } System.out.println(sum); } } }