+ 1
Can anyone explain this java statement and the value of x after evaluating::- where int x=4
x+=(x++)+(++x)+x
2 Réponses
+ 3
To understand, let us rewrite the equation. So
x+=(x++)+(++x)+x actually means
x = x + (x++) + (++x) + x
At the start, x is 4. So
x = 4 + (x++) + (++x) + x
(x++) will use x (4) then increment x, making it 5. So
x = 4 + 4+ (++x) + x
(++x) will increment x (5) making it 6, then use x. So
x = 4 + 4 +6 + x
And x is now 6. So
x = 4 + 4 + 6 + 6
Which is 20.
Thus x = 20.
+ 1
Thanks