Saurabh Dwivedy

Greenhorn
+ Follow
since May 02, 2021
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Saurabh Dwivedy

Thank you for your educative post! I learnt a few new things. I’m not a Java expert so this was quite insightful for me. Thank you!
3 years ago

Alexander Zotz wrote:OCP Java SE11 Complete study guide, site 86 is following Question:



i thought the post-decrement would change the value after the calculation, like this:
1. ++lion
2. 4 * 5 / 4
3. lion--
after getting the result (2), i would decrement lion.

But in the explanation they do the post-decrement first. I cant understand why..
1. lion--
2. ++lion
3. 3 * 5 / 3

Can someone explain me this?



In the numerator ++ has higher precedence so it increases the value of lion to 4, then multiplies. In the denominator, it divides with the incremented value of lion first and then decrements back to 4. Try changing it to --lion in the denominator;