import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); String str = input.nextLine(); char c[] = str.toCharArray(); long sum = 0; for (int i = 0; i < c.length; i++) { if (c[i] >= '0' && c[i] <= '9') { sum += (c[i] - '0') * Math.pow(16, c.length - i - 1); } else { sum += (c[i] - 'A' + 10) * Math.pow(16, c.length - i - 1); } } System.out.println(sum); } }
原文地址:http://blog.csdn.net/qq_16542775/article/details/44939705