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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты