java通过16进制转10进制的算法实现
进制转换
http://www.nowcoder.com/questionTerminal/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine(); String num = str.substring(2,str.length()); int result = 0; int power = 1; for(int i = num.length() - 1; i >= 0; i--){ char c = num.charAt(i); if(c >= '0' && c <= '9'){ result += (c - '0') * power; }else if (c >= 'A' && c <= 'F'){ result += (c - 'A' + 10) * power; } power *= 16; } System.out.println(result); } sc.close(); } }