学习日记Day16 数据类型扩展及面试题

//整数扩展 进制: 二进制0b前缀表示  十进制  八进制0  十六进制0X
   int i = Ob2;
   int i1 = 010;//八进制0 
   int i2 = 0X10;//十六进制0X

//====================================================================
  float d1 = 0.1d;//0.1
  double d2 = 1.0/10;//0.1
 
System out printin(d1==d2);//结果是false,因为浮点数有误差

  float d1 = 232222222222211215f;
  double d2 = d1+1;//结果是ture

System out printin(d1==d2);//结果是ture,因为浮点数有误差

//float double ,浮点数有限、离散、舍入误差、大约、接近但不等于
//最好完全避免使用浮点数进行比较
//最好完全避免使用浮点数进行比较
//最好完全避免使用浮点数进行比较


public class Demo5 {
    public static void main(String[] args) {
        char a ='中';  //后面要记得打上“;”,char 表示单字符,用单引号标注,只能储存一个字符
     String b ="中国";  /*String 表示字符串,用双引号标注,可以储存0个或多个字符,
        其实string类型就是char类型的数组表现形式*/

      char c1 = 'a';
      char c2 = '中';

        System.out.println(c1);//输出结果为a
        System.out.println((int)c1);//这里c1的输出被强制转换成数字,
        
        System.out.println(c2);//输出结果为中
        System.out.println((int)c2);//这里c2的输出被强制转换成数字
        
             //说明所有的字符本质还是数字
        //编码  Unicode 表(a = 97 A = 65) 2字节 0 —— 65536 Excel 
         //  U0000  UFFFF
         char c3 = '\u0061';
     System out printin(c3); //输出结果=a

//转义字符
 // \t  制表符
//  \n  换行
//......等等

        System out printin("Hello\tWorld");//输出结果为Hello World

//布尔值扩展
  boolean flag = ture;
   if(flag==ture){};//如果flag=真就进行什么下一步操作(在大括号内输入),新手操作
   if(flag){};//老手操作,与上一行同意思
   //Less is More! 代码要精简易读!
posted @ 2021-03-12 14:03  小老豆  阅读(46)  评论(0)    收藏  举报