JAVA学习的小知识点

    xiaoxiao2021-03-25  112

    boolean类型的存储长度:

    4字节,32bits 当被映射到java虚拟机的编译器的int类型时,为了能对齐,编译器必须使用相同的编码。所以是32位的符号二进制补码整数。boolean a=true

    1字节,8bits 做数组时boolean[] b = new boolean[10];

    类型转换

    boolean类型和其他类型不能转换

    int x = 5; double y = 6; // boolean b = (boolean)(x = y);//报错 boolean b = (boolean)(x == y);

    int、float、double转换

    int i = 9; System.out.println( 1 > 0 ? i : 7.0);

    输出结果是:9.0 因为前面是7.0,类型要一致,所以int转换成double。

    System.out.println(5 + 7.0 + "and" + 5 + 7);

    输出的结果是:12.0and57 从左到右,5+7.0,int转换成double型,所以是12.0,12.0+“and”,12.0转换成string类型,”12.0and”+5 +7,5和7都转换成string型。

    转载请注明原文地址: https://ju.6miu.com/read-23757.html

    最新回复(0)