Day01-6 数据类型
强类型语言
-
要求变量的使用要符合规定,所有变量都必须先定义后才能使用
java数据类型的两大类
基本数据类型
-
数值类型
-
整数类型
byte占1个字节范围:-128-127
shout占2个字节范围:-32768-32767
int占4个字节范围:-2147483648-2147483647
long占8个字节范围:-9223372036854775808-9223372036854775807
-
浮点类型
float占4个字节
double占8个字节
-
字符类型
char占2个字节
-
-
布尔类型
boolean占1位其值只有true和false两个
引用数据类型
-
类
-
接口
-
数组
整数拓展
//进制:二进制(0b)、八进制(0)、十进制、十六进制(0x)
int i = 10;
int i2 = 010;//八进制0
int i3 = 0x10;//十六进制0x 0~9 A~F
浮点数拓展
//银行业务怎么表示钱
//BigDecimal 数学工具类
//float 有限 离散 舍入误差 大约 接近不等于
//double
//最好完全避免使用浮点数进行比较!
//最好完全避免使用浮点数进行比较!
//最好完全避免使用浮点数进行比较!
float f = 0.1f;//0.1
double d = 1.0/10;//0.1
System.out.println(f==d);
//输出结果为false
float d1 = 2313131313131313f;
float d2 = d1 + 1;
System.out.println(d1==d2);
//输出结果为true
字符拓展
//字符拓展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
//输出a
System.out.println((int)c1);
//输出97
System.out.println(c2);
//输出中
System.out.println((int)c2);
//输出20013
//所有的字符本质还是数字
//编码 Unicode 表:(97 = a 65 = A) 2字节 65536 Excel 2的16次方 = 65536
// U0000 UFFFF
char c3 = '\u0061';
System.out.println(c3);
//输出a
//转义字符
// \t 制表符
// \n 换行
System.out.println("Hello\tWorld");
//输出Hello World
System.out.println("Hello\nWorld");
/*输出
Hello
World
*/
String sa = new String("hello world");
String sb = new String("hello world");
System.out.println(sa==sb);
//输出为false
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! 代码要精简易读

浙公网安备 33010602011771号