+ 1

Can anyone explain this java statement and the value of x after evaluating::- where int x=4

x+=(x++)+(++x)+x

17th Jul 2018, 5:11 PM
Neha Dhar
Neha Dhar - avatar
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.
17th Jul 2018, 5:32 PM
Andre Daniel
Andre Daniel - avatar
+ 1
Thanks
17th Jul 2018, 5:35 PM
Neha Dhar
Neha Dhar - avatar