1. 程式人生 > 其它 >資料型別擴充套件及面試題

資料型別擴充套件及面試題

package java基礎;

import java.awt.PageAttributes.OriginType;

public class Data {public static void main(String[] args) {
//整數拓展 進位制 二進位制0b 八進位制0 十進位制 十六進位制0x
int i = 0b10;
int i2= 010;
int i3= 10;
int i4 = 0x10;
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println(i4);
System.out.println("====================");

 

 


//===============================================
//面試題:銀行業務如何表示 錢? bigdecimal 數學工具類
//================================================
//浮點數拓展 特性 :有限 離散 舍入誤差 接近但不等於
//最好完全避免使用浮點型別進行比較
//最好完全避免使用浮點型別進行比較
//最好完全避免使用浮點型別進行比較
//如果需要進行計算並且不能讓它有誤差,就用java定義好的一個類,叫"bigdecimal"
float f=0.1f;
double d=0.1;
System.out.println(f);
System.out.println(d);
System.out.println(d==f);

 

 


//===================================================
//字元拓展
//===================================================
System.out.println("====================");
char a1 = 'a';
char a2 = '中';
char a3 = 'A';
System.out.println(a1);
System.out.println((int)a1);//強制轉換
System.out.println(a2);
System.out.println((int)a2);//強制轉換
System.out.println((int)a3);
//所以的字元本質還是數字,因為在電腦裡只能儲存數字,字元是通過unicode編碼轉化出來的。
//編碼 unicode (a=97 A=65)佔2位元組 範圍是2的16次方
//char a4='/u0061';; System.out.println(a4);本該輸出a 因為Unicode中/u0061=a,
//但報錯說--Invalid character constant(無效字元常量)問題待定

 

 

//===================================================
//轉義字元
//===================================================
// \n 換行本義是游標往下一行(不一定到下一行行首)。n 的英文newline,控制字元可以寫成LF,即Line Feed
// \t 製表符
// \b 退格
// \r 回車 回車 \r 本義是游標重新回到本行開頭。r 的英文return,控制字元可以寫成CR,即Carriage Return
// \f 換頁
// \\ 反斜槓
// \'
// \"
System.out.println("====================");
System.out.println("hello\nworil");
System.out.println("hello\tworil");
System.out.println("hello\bworil");
System.out.println("hello\rworil");
System.out.println("hello\fworil");
System.out.println("hello\\woril");
System.out.println("hello\'woril");

//===================================================
//物件 從記憶體分析
//===================================================
System.out.println("====================");
String aa="hello,woril";
String ab = "hello,woril";
System.out.println(aa==ab);//true
String ac = new String("hellom=,woril");
String ad = new String("hellom=,woril");
System.out.println(ac==ad);//false
//都是地址,第二個是不同的兩個空間,第二個是同一個空間,因為字串是常量。

 


//==================================================

//布林擴充套件
//===================================================、
boolean flag =true;
if (true) {//if(如果)如果它是true就執行{}裡的程式碼,否則執行else{}裡面的程式碼;



}else {
//程式碼要精簡易讀
}
}

}