我觉的应该应用大数操作
进制转换
http://www.nowcoder.com/questionTerminal/8f3df50d2b9043208c5eed283d1d4da6
//1,反转字符数组 //2,大数操作 import java.math.BigInteger; import java.util.*; public class hexadecimalToInt { public static BigInteger bigIntegerPow(int i){ if(i==0){ return BigInteger.ONE; } BigInteger value=BigInteger.valueOf(16); for(int j=0;j<i-1;j++){ value=value.multiply(BigInteger.valueOf(16)); } return value; } public static void reverseCharArray(char [] array){ for(int i=0;i<array.length/2;i++){ char temp=array[i]; array[i]=array[array.length-i-1]; array[array.length-i-1]=temp; } } public static void main(String [] args){ char [] letter={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; Map<Character,Integer> letterKV=new HashMap<>(); for(int i=0;i<letter.length;i++){ letterKV.put(letter[i],i); } Scanner sc=new Scanner(System.in); while (sc.hasNext()){ String input=sc.nextLine().toUpperCase(); char [] letters=input.substring(2).toCharArray(); reverseCharArray(letters); BigInteger res=BigInteger.ZERO; int i=0; for(char c:letters){ res=res.add(bigIntegerPow(i).multiply(BigInteger.valueOf(letterKV.get(c)))); i++; } System.out.println(res); // input=input.substring(2); // System.out.println(Integer.parseInt(input,16)); } } }