+ 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, 4:01 PM
Neha Dhar
Neha Dhar - avatar
9 odpowiedzi
+ 1
x = x + x++ + ++x +x =4 + 4 + 5 + 4. =17. Is it correct?
17th Jul 2018, 4:28 PM
Meet Mehta
Meet Mehta - avatar
+ 1
Ok I got it. x = x + x++ + ++x +x =4 + 4(now x=5) + 6 (x=6) + 6 =20. because IN PREFIX ++x FIRST x IS INCREMENTED AND THAN EVALUATION TAKE PLACE. IN POSTFIX x++ FIRST EVALUATION IS DONE AND THAN ITS VALUE IS INCREMENTED. Hope this helps ☺️☺️.
17th Jul 2018, 5:31 PM
Meet Mehta
Meet Mehta - avatar
+ 1
Thanks
17th Jul 2018, 5:33 PM
Neha Dhar
Neha Dhar - avatar
+ 1
MEET MEHTA genius!
17th Jul 2018, 5:36 PM
Satyam
0
That's what I thought earlier. But in the book it is written 20 and when I executed in Java, it too came as 20
17th Jul 2018, 5:09 PM
Neha Dhar
Neha Dhar - avatar
0
If you know how the bracket function here works, please explain
17th Jul 2018, 5:09 PM
Neha Dhar
Neha Dhar - avatar
0
but when I executed in Java, the answer came as 20
17th Jul 2018, 5:12 PM
Neha Dhar
Neha Dhar - avatar
0
The answer 20 is also given in the book
17th Jul 2018, 5:13 PM
Neha Dhar
Neha Dhar - avatar
0
Code?? I didn't get that. well, this was given in our book and can be executed in BlueJ
17th Jul 2018, 5:15 PM
Neha Dhar
Neha Dhar - avatar