Mark Spencers wrote:
final int x= y<10 ? y++ : z++;
This line means if y is less than 10, increment y by 1 and assign it to x, else if y is more or equal 10 increment z by 1.
In your program y is less than 10 and y is incremented first and then assigned to x.
Actually, the original value of y is assigned to x, since a post-increment operator is being used.
So, the initial value of y is 1, then y is less than 10, which means that the expression y++ will be evaluated. The original value is returned (1), and the y value is incremented.
At the end of the program, the values will be: x = 1, y = 2, z = 1
If you use the pre-increment operator instead, then the value is incremented first, and the new value is returned, like this:
Now, x = 2, y = 2, z = 1