一、包裝類對應的基本數據類型
Integer – int
Character – char
二、Integer類的常用用法:
1.輸出Integer基本信息
System.out.println("the max number of int is :"+Integer.MAX_VALUE);
System.out.println("the min number of int is : "+Integer.MIN_VALUE);
System.out.println("the 長度length of int is: "+Integer.SIZE);
System.out.println("the type of int is : "+Integer.TYPE);
輸出:
the max number of int is :2147483647
the min number of int is : -2147483648
the 長度length of int is: 32
the type of int is : int
2.String類型轉int類型
int num1=Integer.parseInt("1");
System.out.println("the value of num1+1="+(num1+1));
String 轉爲int所以可以運算 結果爲:
the value of num1+1=2
3. 進制轉換:
System.out.println("-----------進制-------------");
String str1=Integer.toBinaryString(11);//二進制
System.out.println("the 二進制banary number systen of 11 is : "+str1);
String str2=Integer.toHexString(11);
System.out.println("the 十六進制hexadecimal number system of 11 is : "+str2);
String str3=Integer.toOctalString(11);
System.out.println("the 八進制octonary number system of 11 is:"+str3);
System.out.println("-----------自定義X進制------------");
String str4=Integer.toString(11, 15);
System.out.println("the 十五進制 of 11 is : "+str4);
輸出:
the 二進制banary number systen of 11 is : 1011
the 十六進制hexadecimal number system of 11 is : b
the 八進制octonary number system of 11 is:13
-----------自定義X進制------------
the 十五進制 of 11 is : b