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

3.資料型別的擴充套件以及面試題


public class Demo03資料型別的擴充套件以及面試題 {
public static void main(String[] args) {
//整數拓展: 進位制 二進位制 0b開頭 十進位制 八進位制 0開頭 十六進位制 0x開頭
int i = 10;
int i1 = 0b10; //二進位制 0b開頭
int i2 = 010; //八進位制 0開頭
int i3 = 0x10; //十六進位制 0x開頭 0~9 A~F 15

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

//浮點數拓展 銀行的業務如何表示? 指錢
//BigDecimal 數學工具類
//====================================
// float 的長度是 有限的 長了之後會比較離散 會舍入誤差 會大約 接近但不等於
//最好完全避免使用浮點數進行比較
//最好完全避免使用浮點數進行比較
//最好完全避免使用浮點數進行比較

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

float d1 = 3.1415956985775356f;
float d2 = d1 + 0.0000000000001f;
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 佔2字元 0-65536 以前的 Excel表的 2^16=65536

char c3 ='\u6314';
System.out.println(c3+"大"); //a

//轉義字元
// \t 製表符
// \n 換行

System.out.println("dashi\t999");
System.out.println("dashi\n999");

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

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

//布林值擴充套件
boolean flag = true;
if (flag==true){}
if (flag){}
//Less is More! 程式碼要精簡易讀

}
}