Integer.parseInt(str,radix) radix指定str的进制,然后转化为int型数据,省略radix默认十进制
Double.parseDouble(str,radix)radix指定str的进制,然后转化为double型数据,省略radix默认十进制
Long.parseLong(str,radix)radix指定str的进制,然后转化为Long型数据,省略radix默认十进制

package Content;

import java.util.*;

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

        System.out.println("十进制数据num转化为2,8,16进制字符串:");
        Integer num = scanner.nextInt();
        System.out.println("Number = "+num);
        System.out.println("二进制:"+num.toBinaryString(num));
        System.out.println("八进制:"+num.toOctalString(num));
        System.out.println("十六进制:"+num.toHexString(num));

        System.out.println("\n");

        System.out.println("将指定进制的字符串转化为十进制:");
        String string  = "10000";
        System.out.println("String="+string);
        System.out.println("十进制:"+Integer.parseInt(string));
        System.out.println("二进制:"+Integer.parseInt(string,2));
        System.out.println("八进制:"+Integer.parseInt(string,8));
        System.out.println("十六进制:"+Integer.parseInt(string,16));

    }
}
02-12 15:12