#进制转换#使用Map转换数字并计算
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { //使用HashMap转换 HashMap<Character,Integer> map = new HashMap<Character,Integer>(); map.put('0',0); map.put('1',1); map.put('1',1); map.put('2',2); map.put('3',3); map.put('4',4); map.put('5',5); map.put('6',6); map.put('7',7); map.put('8',8); map.put('9',9); map.put('A',10); map.put('B',11); map.put('C',12); map.put('D',13); map.put('E',14); map.put('F',15); Scanner in = new Scanner(System.in); String str = in.nextLine().substring(2); //每一位上要乘的数字(从个位开始) int n = 1; //十进制结果 int num = 0; for(int i = str.length() - 1; i >= 0 ;i --){ num += map.get(str.charAt(i)) * n; n *= 16; } System.out.println(num); } }