java数据类型(进阶篇)

public class note03 {
public static void main(String[] args) {
//数据类型拓展

    //1.整数拓展

    //进制: 二进制0b   十进制  八进制0  十六进制0x

    int i1 = 10;
    int i2 = 015;//八进制 输出为13
    int i3 = 0b101010;//二进制 输出为42
    int i4 = 0x10f;//十六进制 输出为271
    System.out.println(i1);
    System.out.println(i2);
    System.out.println(i3);
    System.out.println(i4);

    //2.浮点数扩展

    float f = 0.1f;//0.1
    double d = 1/10;//0.1
    System.out.println(f==d);//输出为false

    float f1 = 2213151311131f;
    float f2 = f1 + 1 ;
    System.out.println(f1==f2);//输出为true

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

    //银行业务如何表示呢?
    //运用类  BigDecimal 数学工具类

    //3.字符类拓展
    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   97=a  65=A   2字节 长度为65536
    //U0000  ---  UFFFF
    //excel表格  最大2的16次方,为65536

    char c3 = '\u0062';
    System.out.println(c3);//输出为b

    //转义字符  \t 制表符 \n 换行
    System.out.println("hello\tworld");//输出为hello   world
    System.out.println("hello\nworld");//输出为hello
    //                                        world

    //4.布尔值拓展
    boolean flag = true;
    if (flag==true){}
    if (flag){}
    //两者相同
    //代码要精简易懂

}

}

posted @ 2021-02-18 17:51  stitchkx  阅读(46)  评论(0编辑  收藏  举报