Java Puzzle operator confusion
Why does this
int _=1, __=2; int j = __ ^_^ __, k = __-- -+- _ -+- --__; System.out.println(j + " " + k);print the following?
1 3
This comment has been removed by the author.
ReplyDeleteright expressions in Java are evaluated from left to right (my mistake) so let's think like Java now:
ReplyDeletei = 2
j = 1
i-- + j = 3
i-- + j + --i = 3 (i is already evaluated and equals 1 so --i = 0)
right?
Brillant, you made it look easy. :)
ReplyDelete10
ReplyDelete^01
^10
=
01
2 + 1 + 0 = 3
to compare:
ReplyDeleteJava 1 3
C/C++ 1 4
Python 1 5
Perl 1 3
@Przemyslaw, Thank you for the comparison. ;)
ReplyDelete