資料型別
基本資料型別
整數型別
整數型別
- byte:占1個位元組范圍:-128~127
- short: 占2個位元組范圍:-32768~32767
- int:占4個位元組范圍:-2147483648~2147483647
- long:占8個位元組范圍:-9223372036854775808~9223372036854775807
浮點型別
- float:占4個位元組
- double:占8個位元組
字符型別
char占2個位元組
boolean型別
占1位其值只有true和false兩個
資料型別拓展
package com.kuang.base;
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; //0.1
double d = 1.0/10; //0.1
System.out.println(f==d);//false
float d1 = 23131312312312313f;
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' 2位元組 0 - 65536 Excel 2 16 =65536
//U0000 UFFFF
char c3 = '\u0061';
System.out.println(c3);//a
//轉義字符
//\t 制表符
//\n 換行符
//......
System.out.println("Hello\nWorld");
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! 代碼要精簡易讀
}
}
以上資料來自狂神,鏈接:B站教學視頻
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/304149.html
標籤:Java
