-2

I tried the same code by replacing default values in the code below, I got '-1'. But the actual output is '1'. How???

 int i = (byte) + (char) - (int) + (long) - 1;

            System.out.println(i);
eddie
  • 1,252
  • 3
  • 15
  • 20

1 Answers1

4

i will be evaluated as (+(-(+(-1))), which will be evaluated as (-(-1)), which is 1.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147