4.数据拓展

数据拓展

整数拓展

  • 进制

  • 二进制0b

  • 八进制0

  • 十进制

  • 十六进制0x

int 10;
       int i2 010; //八进制0
       int 011;
       int i3 0x10; //十六进制0x
       int i4 0x11; //十六进制
       int 0b10; //二进制0b
       System.out.println(i); //output 10
       System.out.println(i2); //output 8
       System.out.println(i3); //output 16
       System.out.println(i4); //output 17
       System.out.println(l); //output 9
       System.out.println(o); //output 2

 

浮点数拓展

//浮点数拓展----银行业务字母表示?(钱)
float 0.1f;
       double 1.0/10;

       System.out.println(g==a); //output false. g与a不相等.
       System.out.println(g); //output 0.1
       System.out.println(a); //output 0.1

//=============================================

float 2121121212212f;
       float xs 1;
  System.out.println(x==xs); //output ture. why?
  • 浮点数是有限且离散的。 有舍入误差,表现的是大约的数。是接近但不等于的数。
  • //结论:最好完全避免用浮点数进行比较
    //结论:最好完全避免用浮点数进行比较
    //结论:最好完全避免用浮点数进行比较
    //结论:最好完全避免用浮点数进行比较

 

字符拓展


       char o1 'a';
       char o2 '中';

       System.out.println(o1);
       System.out.println(o2);
       System.out.println((int)o1); //output 97
       System.out.println((int)o2); //output 20013
       //(int)代表强制转化,使字符变成对应的数字形式。
       //表明字符本质还是数字。
       //在unicode表中:97 = a ; 65 = A ;

       char '\u0061';
       System.out.println(j); //output a.

 

转义字符

// \t 制表符
// \n 换行

System.out.println("hello\tworld!");
//output helloworld!
System.out.println("hello\nworld!");
//ouput hello
//world

 

布尔值拓展

boolean flag ture;
       if (flag==ture){} //新手
       if (flag){} //老手 
       //两行代码完全相同。
       //less is more。
posted @ 2020-12-29 21:04  jyurokuya  阅读(89)  评论(0)    收藏  举报