题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String input = in.next(); int len = input.length(); int sum = 0; for (int i = 2; i < len; i++) { int k = 0; if (input.charAt(i) == 'A') { k = 10; } else if (input.charAt(i) == 'B') { k = 11; } else if (input.charAt(i) == 'C') { k = 12; } else if (input.charAt(i) == 'D') { k = 13; } else if (input.charAt(i) == 'E') { k = 14; } else if (input.charAt(i) == 'F') { k = 15; } else k = Integer.parseInt(String.valueOf(input.charAt(i))); sum += k * Math.pow(16,len-i-1); } String output = Integer.toString(sum); System.out.println(output); } }