I know from running the code the answer is 1. I'm not sure why it would be 1. I figured it would be 2. The "if" condition evaluates to true so we run the statement "a=x?1:2". Since x is boolean and a is int, you can't do the assignment, can you?
a=x?1:2 This is an example of the "ternary" or "query-colon" operator, which is presumably what this example code is trying to teach or test. This operator is sort of like an "if", but as an expression not a statement. Imagine it as being equivalent to the following: