What will be printed after compilation and running of the following code?

    double d1 = 1024.0d;
    double d2 = 1.0e-13d;
    double sum = d1 + d2;

    if (sum > d1) {
        System.out.println(">");
    }
    else if (sum < d1) {
        System.out.println("<");
    }
    else if (sum == d1) {
        System.out.println("==");
    }
Explanation
Result of using very big and very small floating point numbers in one arithmetic operation can be unexpected. Double number precision is not big enough to correctly evaluate the calculations.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback