数据类型扩展及面试讲解

数据类型扩展及面试讲解

public class Demo01 {
    public static void main (String[] args){
        System.out.println("========整数拓展======");
       //整数拓展   进制      二进制 :0b      十进制      八进制 :0      十六进制 :0x
        int i=10;
        int i2=010;  //八进制
        int i3=0x10;  //十六进制

        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println("===============================");

    //=====================================
        //浮点数拓展 (银行业务)
        //使用 BigDecimal(数学工具类)
        //float  double  有限   离散的   舍入误差即为大约  接近但不等于
        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较
        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=12312312313f;
        float d2=d1+1;
        System.out.println(d1==d2);//true

        //=========================
        //字符拓展
        //=========================
        System.out.println("==========字符拓展=========");
        char c1='a';
        char c2='中';
        System.out.println(c1);
        System.out.println((int)c1);//强制转换
        System.out.println(c2);
        System.out.println((int)c2);//强制转换
        //强制转换后 c1 c2 均变成数字
        //即搜有的字符本质还是数字
        //编码 Unciode  2字节
        char c3='\u0061';
        System.out.println(c3);
        System.out.println("=========转义字符============");
        //=========================
        //转义字符
        //   \t   制表符号
        //   \n   换行

        System.out.println("holle\tworld");
        System.out.println("=======================");
        String sa=new String ("hello");
        String sb=new String ("hello");
        System.out.println(sa==sb);//false

        String sc="hello";
        String sd="hello";
        System.out.println(sc==sd);//true
        //对象  从内存分析
    }
}

下图为代码的运行结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45814538/article/details/108612229