Java 基礎 之 資料類型

來源:互聯網
上載者:User

標籤:定義   short   方式   http   位元組   直接   long   www.   問題   

http://www.verejava.com/?id=1699255932129

/**java 分為4類8種基礎資料型別 (Elementary Data Type)4類:1. 整型(byte,short,int,long)2. 浮點型(float,double)3. 字元型(char)4. 布爾型(boolean)*/public class BaseDataType{    public static void main(String[] args)    {        //整型 byte, short, int ,long        byte    a1=1;       //byte  占 1個位元組=8位   -2^7~2^7-1(-128~127)        short   a2=10;      //short 占 2個位元組=16位  -2^15~2^15-1        int     a3=100;     //int   占 4個位元組=32位 -2^31~2^31-1        long    a4=1000;    //long  占 8個位元組=64位  -2^63~2^63-1        System.out.println(a1);        System.out.println(a2);        System.out.println(a3);        System.out.println(a4);        /*注意:            1. 整型賦值的時候如果超出了儲存範圍  編譯報錯 丟失精度        */        //浮點型 float , double        double  b1=10.1;    //double    佔8個位元組=64位         float   b2=12.2f;   //float     佔4個位元組=32位          float   b3=(float)13.3;        System.out.println(b1);        System.out.println(b2);        System.out.println(b3);        /*        注意:            1. 浮點型資料預設是 double 型, 如果要賦值給 float型必須經過強制類型轉換,             對於浮點數強制類型轉換兩種方式 一種是: 直接在後面加f 一種是:在前面加(float)        */        //字元型 char 是由單引號括起來的單個字元        char c1=‘a‘;        // char     佔2個位元組=16位        char c2=‘1‘;        char c3=‘好‘;        System.out.println(c1);        System.out.println(c2);        System.out.println(c3);        /*        注意:            1. 在計算的儲存中數字和字母佔1個位元組,而漢字佔2個位元組,                 java為瞭解決這個問題所以定義了char佔2個位元組來統一儲存字母和漢字            2. char 跟 String的區別是 字串是雙引號括起來的多個字元        */        //布爾型 boolean        boolean d1=true;    //布爾型佔1個位元組=8位        boolean d2=false;        System.out.println(d1);        System.out.println(d2);        /*        注意:            1. 布爾類型的true 不能等於1  , false 也不等於0,這個跟c語言要區分        */    }}/*回顧總結:    1.按所屬的資料類型劃分        基礎資料型別 (Elementary Data Type)變數 : 8種基礎資料型別 (Elementary Data Type)(byte,short,int,long,float,double,boolean,char)        引用資料類型變數 : 除了8種基礎資料型別 (Elementary Data Type)的變數都是引用變數    2. String 不屬於基礎資料型別 (Elementary Data Type) 屬於引用資料類型*/

http://www.verejava.com/?id=1699255932129

Java 基礎 之 資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.