第七天打卡

进制

八进制的10是8

十六进制的10是16

char name = '';//是单引号

 String sa = new String(original:"hello world");
 String sb = new String(original:"hello world");

这两句代码为什么会报错??

 public class Demo03 {
     public static void main(String[] args) {
         //整数拓展:进制 二进制0b 十进制 八进制0 十六进制0x
         int i = 10;
         int i2 = 010;//八进制0
         int i3 = 0x10;//十六进制0x 0~9
         System.out.println(i);
         System.out.println(i2);
         System.out.println(i3);
         //====================================
         //浮点数拓展 银行业务表示
         //BigDecimaL 数学工具类
         // float 有限 离散 舍入误差 大约 接近但不等于
         //最好完全避免使用浮点数进行比较
         float f = 0.1f;//0.1
         double d=1.0/10;//0.1
         System.out.println(f==d);
         System.out.println(f);
 
         System.out.println(d);
         float d1 = 2345333333333f;
         float d2 = d1+1;
         System.out.println(d1==d2);
         //====================================
         //字符拓展
         //=======================================
         char c1='a';
         char c2='中';
         System.out.println(c1);
         System.out.println((int)c1);//强制转换
         System.out.println(c2);
         System.out.println((int)c2);//强制转换
         //所有的字符本质还是数字
         //编码 Unicode表:(97=a 65=A) 2字节 0-65536 Excel 2的16次方=65536
           //
         char c3 ='\u0061';
         System.out.println(c3);//a
         //转义字符
         //\t 制表符
         //\n 换行
         System.out.println("Hello\nWorld");
 
         String original;
         String sa = new String(original:"hello world");
         String sb = new String(original:"hello world");//为什么会报错????????
         System.out.println(sa==sb);
         String sc = "hello world";
         String sd = "hello world";
         System.out.println(sc==sd);
         //对象 从内存分析
         //布尔值扩展
         boolean flag = true;
         if(flag==true){}//新手
 
    }
 }

P25

类型转换

小数的优先级一定大于整数

由低到高

byte,short,char->int->long->float->double

运算中,不同类型的数据先转换为同一类型,然后进行运算

强制类型转换

自动类型转换

 public class Demo05 {
     public static void main(String[] args) {
         //操作比较大的时候,注意溢出问题
         //JDK7新特性,数字之间可以用下划线分割
         int money=10_0000_0000;
         int years = 20;
         int total = money*years;//计算溢出
         long total2 = money*years;//默认是Int,转换之前已经出现问题
         long total3 = money*((long)years);
         System.out.println(total3);
         //
    }
 }
 public class Demo04 {
     public static void main(String[] args) {
         int i =128;
         double b = i;//把i转换为byte型
         //强制转换   (类型)变量名 高--低
         //自动转换   低--高
         System.out.println(i);
         System.out.println(b);//byte类型最大为127,大于这个将发生溢出
         /*
         注意点:
         1.不能对布尔值进行转换
         2.不能把对象类型转换为不相干的类型
         3.在把高容量转换到低容量的时候,强制转换
         4.转换的时候可能存在内存溢出,或者精度问题
          */
         System.out.println("============================");
         System.out.println((int)23.7);//23
         System.out.println((int)-45.89f);//-45
         System.out.println("============================");
         char c = 'a';
         int d = c+1;
         System.out.println(d);
         System.out.println((char)d);
    }
 }

 

posted @ 2021-01-15 10:28  豆豆tj  阅读(147)  评论(0编辑  收藏  举报