1. 程式人生 > 其它 >進位制、浮點、字元、布林

進位制、浮點、字元、布林

進位制

int i = 10;
int i2 = 010;//8進位制,0開頭
int i3 = 0x10;//16進位制,0x開頭
int i4 = 0xF;//15,10-15:A-F
System.out.println(i);//10
System.out.println(i2);//8
System.out.println(i3);//16
System.out.println(i4);//15

浮點

//浮點數拓展。銀行業務怎麼表示?錢
//BigDecimal 數學工具類
//=====================================
//float 有限 離散 舍入誤差 大約 接近但不等於
//double
//最好完全避免使用浮點數!!!
//最好完全避免使用浮點數!!!
//最好完全避免使用浮點數!!!
float f = 0.1f;//0.1
double d = 1.0/10;//0.1
System.out.println(f == d);//false

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

字元

//字元拓展?
char c1 = '中';
char c2 = 'A';
System.out.println(c1);//中
System.out.println((int)c1);//20013

System.out.println(c2);//A
System.out.println((int)c2);//65
//所有字元的本質還是數字
//編碼 Unicode Excel 2^16 = 62236
//U0000 UFFFF
char c3 = '\u0061';
System.out.println(c3);//a

//轉義字元
//\t 製表符(空格)
//\n換行
System.out.println("Hello\tWord");//Hello Word
System.out.println("Hello\nWord");//Hello
// Word
String sa = new String("hello word");
String sb = new String("hello word");
System.out.println(sa == sb);//false

String sc = "hello word";
String sd = "hello word";
System.out.println(sc == sd);//true
//物件 從記憶體分析

boolean

boolean flag = true;
if(flag == true){}
if(flag){}
//程式碼要精簡精讀,最好用第二個表示方法