首页 > 编程语言 >Java 数据类型 扩展

Java 数据类型 扩展

时间:2022-10-09 00:46:04浏览次数:54  
标签:Java String 0.1 数据类型 扩展 System int println out

public class Demo2 {
    public static void main(String[] args) {
        //整数拓展 进制 : 二进制 ob ,十进制, 8进制 0, 16进制 0x
        int i = 10;
        int i1 = 010;
        int i2 = 0x10;//16进制 0x  0-9 A-F 16
        System.out.println(i);
        System.out.println(i1);
        System.out.println(i2);
        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);//0.1
        System.out.println(d);//0.1

        float d1 = 23433234323432242f;
        float d2 = d1+1;
        System.out.println(d1 == d2);//true
        System.out.println(d1);
        System.out.println(d2);
        /*=================================
        字符拓展
        =================================
         */
        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);//强制类型转换
        char  c3 = '\u0061';
        System.out.println(c3);
        //所有的字符本质还是数字
        //编码 Unicode 表(97:a 65:A) 2字节  0-65536
        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
        //后续从对象 内存方面进行讲解
    }
}

 结果:

Files\Java\jdk1.8.0_181\jre\lib\rt.jar;D:\学习\JAVA\study\out\production\study" Demo2
10
8
16
=================================
false
0.1
0.1
true
2.34332342E16
2.34332342E16
=================================
a
97
中
20013
a
=================================
false
true

Process finished with exit code 0

标签:Java,String,0.1,数据类型,扩展,System,int,println,out
From: https://www.cnblogs.com/boxer-nofear/p/16770765.html

相关文章