- 1

Tell me how this works please

I am reading java docs and it states: int i = 10; int n = i ++%5; it then askes what are the values after this code is executed. I say well i=10 so 10 and n =i ++ is 11 then %5 answer is 2.. Nope, they say its 11 and 0. How?

4th Apr 2017, 3:01 AM
Opaque Dmr
Opaque Dmr - avatar
2 Answers
+ 6
i = 10 n = i ++ % 5 //i++ is postfix increment //original i value will be used first (10) // and added later after used it //10%5 = 0 //n = 0 //now the value of i will increased by 1 //therefore i = 11
4th Apr 2017, 3:17 AM
Heng Jun Xi
Heng Jun Xi - avatar
0
Thanks heng!
23rd Apr 2017, 2:11 AM
Opaque Dmr
Opaque Dmr - avatar