關(guān)于Java的8種基本數(shù)據(jù)類型,其名稱、位數(shù)、默認(rèn)值、取值范圍及示例如下表所示:
為了驗(yàn)證表格里的內(nèi)容,在eclipse里運(yùn)行驗(yàn)證代碼如下:
package?com.ce.test;class?Test?{????static?byte?b;????static?short?s;????static?int?i;????static?long?l;????static?float?f;????static?double?d;????static?char?c;????static?boolean?bo;????public?static?void?main(String[]?args)?{??????System.out.println("byte的大?。?+Byte.SIZE??????????????+";默認(rèn)值:"+b??????????????+";數(shù)據(jù)范圍:"+Byte.MIN_VALUE+"?-?"+Byte.MAX_VALUE);??????System.out.println("short的大?。?+Short.SIZE??????????????+";默認(rèn)值:"+s??????????????+";數(shù)據(jù)范圍:"+Short.MIN_VALUE+"?-?"+Short.MAX_VALUE);??????System.out.println("int的大?。?+Integer.SIZE??????????????+";默認(rèn)值:"+i??????????????+";數(shù)據(jù)范圍:"+Integer.MIN_VALUE+"?-?"+Integer.MAX_VALUE);??????System.out.println("long的大?。?+Long.SIZE??????????????+";默認(rèn)值:"+l??????????????+";數(shù)據(jù)范圍:"+Long.MIN_VALUE+"?-?"+Long.MAX_VALUE);??????System.out.println("float的大?。?+Float.SIZE??????????????+";默認(rèn)值:"+f??????????????+";數(shù)據(jù)范圍:"+Float.MIN_VALUE+"?-?"+Float.MAX_VALUE);??????System.out.println("double的大小:"+Double.SIZE??????????????+";默認(rèn)值:"+d??????????????+";數(shù)據(jù)范圍:"+Double.MIN_VALUE+"?-?"+Double.MAX_VALUE);??????System.out.println("char的大?。?+Character.SIZE??????????????+";默認(rèn)值:"+c??????????????+";數(shù)據(jù)范圍:"+Character.MIN_VALUE+"?-?"+Character.MAX_VALUE);??????System.out.println("boolean的大?。?+Byte.SIZE??????????????+";默認(rèn)值:"+bo??????????????+";數(shù)據(jù)范圍:"+Byte.MIN_VALUE+"?-?"+Byte.MAX_VALUE);????}}
在控制臺(tái)輸出結(jié)果如下圖所示:
此處為什么輸出char的數(shù)據(jù)范圍不是0-65535呢?
Java中的char類型由兩個(gè)字節(jié)即十六位來(lái)表示,因?yàn)槭菬o(wú)符號(hào)數(shù),所以為2的16次方,數(shù)值范圍就為:0-2^16-1;
以上就是長(zhǎng)沙一度軟件培訓(xùn)java培訓(xùn)機(jī)構(gòu)的小編針對(duì)“八種java基礎(chǔ)數(shù)據(jù)類型”的內(nèi)容進(jìn)行的回答,希望對(duì)大家有所幫助,如有疑問(wèn),請(qǐng)?jiān)诰€咨詢,有專業(yè)老師隨時(shí)為你服務(wù)。