File size: 1,342 Bytes
0284885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package Integer_package;

public class Integer_demo2 {
    public static void main(String[] args) {
        /*
        public static String toBinaryString (int i)     得到二进制
        public static String toOctalString (int i)      得到八进制
        public static String toHexString (int i)        得到十六进制
        public static int parseInt (String s)           将字符串类型的整数转成int类型的整数
         */

        //1、把整数转成二进制、十六进制
        String str1 = Integer.toBinaryString(100);
        System.out.println(str1);

        //2、把整数转成八进制
        String str2 = Integer.toOctalString(100);
        System.out.println(str2);

        //3、把整数转成十六进制
        String str3 = Integer.toHexString(100);
        System.out.println(str3);

        //4、将字符串类型的整数转成int类型的整数
        int i = Integer.parseInt("123");
        System.out.println(i);
        //细节1:
        //在类型转换的时候,括号中的参数只能是数字不能是其他,否则代码会报错
        //细节2:
        //8种包装类当中,除了Character都有对应的parseXxx的方法,进行类型转换
        String s = "true";
        boolean b = Boolean.parseBoolean(s);
        System.out.println(b);
    }
}