+ 1
How this java code will work?
Plz explain this code https://www.sololearn.com/post/1003075/?ref=app
2 Answers
+ 2
int x = 1;
int y = 2;
y += --x + y - x;
// y = y + (--x + y - x)
// y = 2 + (0 + 2 - 0)
// y = 2 + (2)
System.out.println(y); // 4
+ 2
if x is 1 and y is 2 to start.
then y(2) is added to (pre-decremented) x(0). Since x is now 0 the rest of the equation should make sense
2 += (1 - 1) + 2 - 0 = 4