Java笔记第四课:数据类型扩展。

数据类型扩展

整数拓展

进制:

二进制0b 十进制 八进制0 十六进制0x

public class dada {
   public static void main(String[] args) {
       int i = 0b10;//二进制0b
       int i2 = 010;//八进制0
       int i3 = 0x10;//十六进制0x 0~9 A~F
       System.out.println(i);
       System.out.println(i2);
       System.out.println(i3);
  }
}

//输出
 2
 8
 16

浮点数拓展

float

public class dada {
   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);
       System.out.println(d);

       float d1 = 1234542316854564564f;
       float d2 = d1 + 1;
       System.out.println(d1==d2);//true
  }
}

 

有限 离散 摄入误差 大约 接近但不等于

注:最好完全使用浮点数进行比较

银行相关的业务必须得用BigDecmal(数学工具类)


字符拓展

所有字符本质还是数字

编码Unicode (表:97 = a ,65 = A )2字节 0-65536 Excel 2 16 =65536

    public class dada {
   public static void main(String[] args) {
       char ass1 ='a';
       char ass2 ='唯';
       System.out.println(ass1);
       System.out.println((int)ass1);//强行置换
       System.out.println(ass2);
       System.out.println((int)ass2);//强行置换

  }
}
Connected to the target VM, address: '127.0.0.1:60658', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:60658', transport: 'socket'
a
97

21807

Process finished with exit code 0

转义字符

public class dada {
   public static void main(String[] args) {
       System.out.println("Hello\tWord");// \t=制表符
       System.out.println("Hello\nWord");// \n换行
  }
}
Connected to the target VM, address: '127.0.0.1:60852', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:60852', transport: 'socket'
Hello Word
Hello
Word

Process finished with exit code 0

布尔值扩展

public class dada {
   public static void main(String[] args) {
       boolean sb = true;
       if (sb==true){}
       if (sb){}
// if (sb==true){} = if (sb){}
//Less is More! 代码要精简!!
}
}

 

posted on 2021-12-24 22:05  今岛唯  阅读(39)  评论(0)    收藏  举报