Java語言基本數(shù)據(jù)類型大小

類型 字節(jié)數(shù) 位數(shù) 取值范圍
Byte 1 8 -128~127
char 2 16 -2的15次方到2的15次方-1
shout 2 16 -2的15次方到2的15次方-1
int 4 32 -2的31次方到2的31次方-1
long 8 64 -2的63次方到2的63次方-1
Float 4 32 3.402823e+38 ~ 1.401298e-45
double 8 64 1.797693e+308~ 4.9000000e-324
boolean 1(前7位是0) 1 0~1
 public static void main(String[] args) throws UnsupportedEncodingException {
        //負(fù)數(shù)的2進(jìn)制計(jì)算方法是,除了符號(hào)位之外,取反再加1。
        // 所以1000 0000 ,除符號(hào)位之后,取反得到 111 1111 ,再加1得到:1000 0000 =  -128    符號(hào)位要記得。
        //而1111 1111 ------取反----->   1000 0000  --------加1--------->  1000 0001 = -1這邊符號(hào)位還在。
        int length = new String("付").getBytes("GBK").length;
        System.out.println(Byte.MAX_VALUE); //127       1111 1111 去掉符號(hào)位 111 1111 =2的7次方減1 =2^7-1
        System.out.println(Byte.MIN_VALUE); //-128
        System.out.println(Short.MAX_VALUE); //32767
        System.out.println(Short.MIN_VALUE);  //-32768
        System.out.println(Integer.MAX_VALUE);//2147483647
        System.out.println(Integer.MIN_VALUE);  //-2147483648
        System.out.println(Long.MAX_VALUE);  //9223372036854775807
        System.out.println(Long.MIN_VALUE);  //-9223372036854775808  總共19long類型的數(shù)字

    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容