Huaweiマシンテストの質問5の変換

タイトル説明
16進数を受け入れ、値の10進数表現を出力するプログラムを記述します。(同時に入力される複数のグループ)

入力の説明:
16進数の数値文字列を入力します。

出力の説明:
値の10進文字列を出力します。

例1の
入力

0xA
出力

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));
        }
    }
}
オリジナルの記事を3件公開 Likes0 Visits12

おすすめ

転載: blog.csdn.net/StarSky_boy/article/details/105426688