Huawei machine test questions 5 conversion

Title Description
Write a program that accepts a hexadecimal number and outputs the decimal representation of the value. (Multiple groups input at the same time)

Input description:
Enter a hexadecimal numeric string.

Output description:
Output the decimal string of the value.

Example 1
input

0xA
output

10

public class Mine {

    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String num = sc.nextLine();
            //去掉前两位的0x
            System.out.println(Integer.parseInt(num.substring(2), 16));
        }
    }
}
Published 3 original articles · Likes0 · Visits12

Guess you like

Origin blog.csdn.net/StarSky_boy/article/details/105426688