热点机考-进制转换

95 阅读1分钟
题目

输入描述:

输入一个十六进制的数值字符串    如0xAA

输出描述:

输出该数值的十进制字符串。  如255
public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    while(sc.hasNext()){
        List<String> result = new ArrayList<>();
        String str = sc.nextLine();
        result.add(str.replace("0x", ""));

        for (String s : result) {
            int i = Integer.parseInt(s, 16);
            System.out.println(i);
        }

    }
}

测试结果:

image.png