JAVA基础数据类型拓展内容

public class demo02 {
    public static void main(String[] args) {
//        整数拓展 : 二进制0b   十进制   八进制0   十六进制0x
        int i = 0b11;  //二进制
        int i1 = 11;  //十进制
        int i2 = 011;  //八进制
        int i3 = 0x11;  //十六进制 0-9用正常数字表示,10-15用A-F表示
        System.out.println(i);
        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);

//        浮点数拓展 : float有限,离散,有舍入误差,接近但不等于
//        最好完全避免使用浮点数进行比较
//        银行业务(钱)怎么表示?  BigDecimal 数学类工具
        float f = 0.1f;
        double d = 1.0/10;
        System.out.println(f);  //输出为0.1
        System.out.println(d);  //输出为0.1
        System.out.println(f==d);  //输出为false

        float f1 = 21355999523685f;
        float f2 = f1 + 1;
        System.out.println(f1==f2);  //输出结果为true(f1数字要足够大)


//        字符拓展 :所有字符的本质还是数字
//        字符强制转换编码 :Unicode表:(97 = a  65 = A)
        char c1 = '中';
        char c2 = 'A';
        System.out.println(c1);  //输出为:中
        System.out.println((int)c1);  //强制转换 输出为:20013
        System.out.println(c2);  //输出为:A
        System.out.println((int)c2);  //强制转换 输出为:65

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

        System.out.println("Hello\nWorld!");  //换行
        System.out.println("Hello\tWorld!");  //制表

//        对象:从内存分析
        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){}  //这两行代码其实是一样的

        
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值