value: 11 result: 20
The example program fragment:
int value = 10 ; int result = 0 ; result = value++ * 2 ; System.out.println("value: " + value + " result: " + result );
is equivalent to this program fragment:
int value = 10 ; int result = 0 ; result = value * 2 ; value = value + 1 ; System.out.println("value: " + value + " result: " + result );
The second version is one statement longer, but easier to understand. Use the increment operator only where it makes a program clearer, not merely to save typing. Using the increment operator without enough thought results in very confusing code.
The increment operator must be applied to a variable. It cannot be applied to a larger arithmetic expression. The following is incorrect:
int x = 15; int result; result = (x * 3 + 2)++ ; // Wrong!