The following simplest Java code returns some unexpected output. Let’s look at it.
package interchange;
final public class Main
{
public static void main(String[] args)
{
int x = 15;
int y = 20;
x^=y^=x^=y;
System.out.println("x = " + x + "; y = " + y);
}
}
The code above displays the following output on the console.
x = 0; y = 15
How?
According to operator precedence it can be rewritten like this