Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Let the value of integer variable n be 2, and after the statement "n+=n-=n*n" is executed, the value of n is _ _ _
Let the value of integer variable n be 2, and after the statement "n+=n-=n*n" is executed, the value of n is _ _ _
Assignment statement, run from right to left in turn:

So:

int? n = 2;

n+= n-= n * n;

Equivalent to:

n-= n * n;

n+= n;

Then it is equivalent to:

n = n-n * n;

n = n+n;

Because n is initialized to 2:

n = n-n * n = 2-2 * 2 =-2;

n = n+n =-2+(-2)= =-4;

So the final result is -4.