数据类型扩展
进制
-
二进制 0b
-
十进制
-
八进制 0
-
十六进制 0x 0~9=A~F
浮点数拓展
-
float
-
double
public class Demo01{
public static void main(String[] args){
float f = 0.1f;//0.1
double d = 1.0/10;//0.1
System.out.println(f == d);//false
System.out.println(f);//0.1
System.out.println(d);//0.1
}
}public class Demo02{
public static void main(String[] args){
float d1 = 23131312312312313f;
float d2 = d1 + 1;
System.out.println(d1 == d2);//true
}
}浮点数字长有限,离散的,会舍入误差,接近但不等于,大约
因此
最好完全避免用浮点数进行比较
比如银行业务(使用大数类型:BigDecimal ;是一个数学工具类)
字符拓展
public class Demo03{
public static void main(String[] args){
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表)
转义字符:\u,将数字转字符;比如 \u0061 = a
\t, 制表符
\n,换行符
public class Demo04{
public static void main(String[] args){
String sa = new String(original:"hello world");
String sb = new String(original:"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){
}其中if (flag == true)可以写成if (flag)
-

浙公网安备 33010602011771号