输出:没有错误您可能分配了太多内存 任何人都可以详细解释

查看以下源代码


class Test

{

    public static void main(String[] args)

    {

        Double object = new Double("2.4");

        int a = object.intValue();

        byte b = object.byteValue();

        float d = object.floatValue();

        double c = object.doubleValue();


        System.out.println(a + b + c + d );


    }

}

输出:没有错误您可能分配了太多内存


谁能详细解释一下


茅侃侃
浏览 142回答 2
2回答

慕的地10843

将您的代码更改为Double object = new Double("2.4");int a = object.intValue();byte b = object.byteValue();float d = object.floatValue();double c = object.doubleValue();System.out.println(a);        System.out.println(a + b);        System.out.println(a + b + c);        System.out.println(a + b + c + d );   并探索

繁星淼淼

如果有人仍在寻找为什么 15 位小数精度出现的答案。public class JavaExample {    public static void main(String[] args) {        Double object = new Double("2.4");        int a = object.intValue();        byte b = object.byteValue();        float c = object.floatValue();        double d = object.doubleValue();        float e = object.floatValue();        double f = object.doubleValue();        System.out.println("int :"+a);                System.out.println("int and byte addition :"+(a + b));                System.out.println("int, byte and float addition :"+(a + b + d));                System.out.println("int, byte, float and double addition :"+(a + b + c + d));           System.out.println("float and double addition :"+(c + d));          System.out.println("float and float addition :"+(c + e));         System.out.println("double and double addition :"+(d + f));         System.out.println("float and double addition :"+(e + f));     }}Output:int :2int and byte addition :4int, byte and float addition :6.4int, byte, float and double addition :8.800000095367432float and double addition :4.800000095367432float and float addition :4.8double and double addition :4.8float and double addition :4.800000095367432
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java