题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String num = in.nextLine(); // System.out.println(num.substring(2)); char[] res = num.substring(2).toUpperCase().toCharArray(); int result = 0; for (int i = res.length - 1; i >= 0; i--) { int sq = (res.length - 1 - i); int current = 0; switch (res[i]) { case 'A': current = 10; break; case 'B': current = 11; break; case 'C': current = 12; break; case 'D': current = 13; break; case 'E': current = 14; break; case 'F': current = 15; break; default: current = Integer.valueOf(String.valueOf(res[i])); } result += current * Math.pow(16, sq); // System.out.println("current="+current); // System.out.println("sq="+sq); // System.out.println("result="+result); } System.out.println(result); } }