数据类型拓展

数据类型拓展

整数拓展

  • 二进制0bxx 八进制0xxx 16进制0x xx 0~9 A~F(10~15)

浮点数拓展

  • 浮点数是 离散的 接近但不等于(二进制下无限,四舍五入),如12.3=12.2999999999999

  • 使用BigDecimal(数学工具类)这类来精确计算

字符拓展

  • 所有的字符本质上都是数字

  • 转义字符\ \t制表符 \n换行

 

public class Demon1 {
   public static void main(String[] args) {
       //整数拓展 进制 二进制:0b 八进制:0 十六进制:0x
       int num1=0b0001;
       short num2=010;
       long num3=0x1F;//16进制 0~9 A~F
       System.out.println(num1);
       System.out.println(num2);
       System.out.println(num3);
       System.out.println("=======================");

       //浮点数拓展
       float i1=0.1F;//float是离散的 有限的 接近但不等于那个数
       double i2=0.1;
       //========================
       //银行算钱
       //========================
       System.out.println(i1);
       System.out.println(i2);
       System.out.println(i1==i2);//i1!=i2
       //最好完全避免使用浮点数数进行比较数字
       //BigDecimal 数学工具类使用这个就是确切的了
       System.out.println("======================================");
       float f1=121213132132f;//float是4个字节,数字超过21亿后将会相同所以显示true
       float f2=f1+1;
       System.out.println(f1==f2);
       System.out.println(f1);
       System.out.println(f2);

       //字符拓展
       char c1='Z';
       char c2='中';
       System.out.println(c1);
       System.out.println((int)c1);//强制转换
       System.out.println(c2);
       System.out.println((int)c2);//强制转换

       //所有的字符本质还是数字
       //编码 Unicode 2个字节
       //转义字符\
       // \t 制表符
       // \n 换行
       System.out.println("hellow\nWorld");//转义制表符
       System.out.println("=============================");
       System.out.println("Hellow\tWorld");//转义空格
       System.out.println("=============================");
       System.out.println("=============================");
       String s1=new String("qfqf qchh");//s1内存地址与s2不一样
       String s2=new String("qfqf qchh");
       System.out.println(s1==s2);//所以是false

       System.out.println("=============================");
       String s3="hello";
       String s4="hello";
       System.out.println(s3==s4);
  }
}
运行结果:
//整数拓展:    
1
8
31
=======================
//浮点数拓展:
0.1
0.1
false
======================================
true
1.21213133E11
1.21213133E11
//字符拓展:  
Z
90

20013
//转义字符:
hellow
World
=============================
Hellow World
=============================
=============================
false
=============================
true

Process finished with exit code 0

 

posted @ 2021-02-21 22:37  kang_dg  阅读(65)  评论(0)    收藏  举报