整数、浮点数等拓展

  • 拓展
package com.zhen.base;

public class Demo06 {
    public static void main(String[] args) {

        //整数拓展;   进制   二进制0b     八进制0   十六进制0X
        int x = 10;
        int y = 010;    //二进制
        int z = 0x10;   //十六进制   0-9 A-F F=15

        System.out.println(x);   // 10
        System.out.println(y);   // 8
        System.out.println(z);   // 16
        System.out.println("============================");

        //浮点拓展
        //float 有限 离散 舍入误差 大约 接近但不等于

        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较

        float f = 0.1f;
        double d = 0.1;
        System.out.println(f==d);  //false
        System.out.println(f);
        System.out.println(d);

        float f1 = 132151212f;
        float f2 = f1 +1;
        System.out.println(f1==f2);  //true


        System.out.println("============================");

        //字符拓展


        char c1 = 'a';
        char c2 = '中';
        System.out.println(c1);
        System.out.println((int)(c1));   //97    强制转换
        System.out.println(c2);
        System.out.println((int)c2);     //20013    强制转换

        //所有的字符本质是数字
        //编码 Unicode占2字节 0 - 65536
        //Unicode表: 97 = a

        char c3 = '\u0061';
        System.out.println(c3);   //a

        //转义字符
        System.out.println("Hello,world");
        System.out.println("Hello world");
        System.out.println("=================");
        System.out.println("Hello\tworld");  //Hello	world
        System.out.println("Hello\nworld");  //Hello
                                            //world


        System.out.println("=================");

        String sa = new String("hello world");
        String sb = new String("hello world");
        System.out.println(sa==sb);  //false  比较的是地址值

        String sc = "hello world";
        String sd = "hello world";
        System.out.println(sc==sd);   //true  比较的是值 常量
        //如果比较的对象是基本数据类型,则比较的是数值是否一致;
        // 如果比较的是引用数据类型,则比较的是对象的地址值是否一致
        //对象  从内存分析




//===============================================================
        //布尔值拓展
        boolean flag = true;
        if (flag==true){}   ;
        if(flag){};
        //以上代码含义一样

        }
    }


posted @ 2022-04-15 21:02  北落君  阅读(30)  评论(0)    收藏  举报