Given the program fragment:

double p = Double.POSITIVE_INFINITY;
double n = Double.NEGATIVE_INFINITY;

    ((long) p > (long) n) + " " +
    ((int) p > (int) n) + " " +
    ((short) p > (short) n) + " " +
    ((char) p > (char) n) + " " +
    ((byte) p > (byte) n));
What will be printed when this code is executed?
This example demonstrates the principle of converting real data types to integer. At first, the cast to int (or long) is performed, and then value is just truncated if we need a byte, char or short. That's why byte and short behave strangely (for example -inf -> 0x80000000 -> 0x00=0, and +inf -> 0x7FFFFFFF -> 0xFF=-1)

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Зареєструйся Зараз
або Підпишись на майбутні тести