I want to solve this expression
// Java program
class HelloWorld {
public static void main(String[] args) {
int i = 5;
i += i++ + i-- + i--;
System.out.println(i);
}
}
The confusion arises from the order of operations. The output is 21 because the post-increment and post-decrement operations are evaluated after the current value of ‘i’ is used. Thus, ‘i’ is added to itself before the increments and decrements occur. This is why the result differs from the expected 19.
New contributor
Nikhil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.