Search code examples
javaascii

Java output from (y*++z / (z-- -6.0) + 'd'*0.5);


double x = 4.0;
long y = 10;
byte z = 8;
char c = 'd';

System.out.println (y*++z / (z-- -6.0) + 'd'*0.5);

The result is 80.0, but I don't know why?

d is ASCII-Code Number 100.
First term is 80 second term is 2 third term is 50 ?


Solution

  • First term is 30, second is 50. Totals to 80.

    'd' = 100

    100 * 0.5 = 50

    ++z = 9

    y * ++z = 10 * 9 = 90

    z-- = 8, but after the operation. In the operation it is still 9

    z-- - 6.0 = 9 - 6 = 3

    90 / 3 = 30

    30 + 50 = 80