數據類型及拓展(Java)


數據類型及拓展(Java)

 

public class Demo03 {
   public static void main(String[] args) {
       //整數拓展: 進制   二進制0b   十進制   八進制0   十六進制0x
       int i = 10;
       int i2 = 010;   //八進制0
       int i3 = 0x10;  //十六進制0x


       System.out.println(i);
       System.out.println(i2);
       System.out.println(i3);
       System.out.println("====================");
       //===============================================


       //浮點數拓展

       //BigDecimal 數學工具類


       //float     有限 離散 舍入誤差 大約 接近但不等於
       //double

       //最好完全使用浮點數進行比較
       //最好完全使用浮點數進行比較
       //最好完全使用浮點數進行比較

       float f = 0.1f;
       double d = 1.0/10;
       System.out.println(f==d);//false
       System.out.println(f);
       System.out.println(d);

       float d1 = 232323232332f;
       float d2 = d1+1;
       System.out.println(d1==d2);//true

       //===================================
       //===================================
       //字符拓展
       System.out.println("=======================");

       char c1 ='a';
       char c2 = '飛';
       System.out.println(c1);
       System.out.println((int)c1);// 強制轉換

       System.out.println(c2);
       System.out.println((int)c2);//強制轉換

       //所有的字符本質還是數字
       //編碼Unicode 表 :(97=a 65=A)

       //U0000 UFFFF

       char c3 = '\u0061';
       System.out.println(c3);//a

       //轉義字符
       // \t   制表符
       // \n   換行
       //...
       System.out.println("Hello\tWorld ");

       //
       System.out.println("=======================");

       String sa = new String("hello world");
       String sb =new String("hello world");
       System.out.println(sa==sb);//flase

       String sc = "hello world";
       String sd = "hello world";
       System.out.println(sc==sd);//true
       //對象   內存分析


       //布爾值拓展
       boolean flag = true;
       if (flag==true){ }   //新手
       if (flag){ }    //老手

       //Less is More!   代碼要精簡易讀

  }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM