Difficulty: Medium
Correct Answer: 2 1 2 0 1 2
Explanation:
Introduction / Context:
This problem exercises switch fall-through behavior across a loop. The case labels are compile-time constants derived from a final short x, allowing x, x-1, and x-2 to be legal case expressions.
Given Data / Assumptions:
Concept / Approach:
For each z, execution begins at the matching case label (if any) and then falls through to the end of the switch, executing all subsequent print statements in order.
Step-by-Step Solution:
Verification / Alternative check:
Add break after each case to see "2 1 0" instead; current omission is deliberate to test fall-through.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming the order of case labels in source must be numeric order—execution starts at the match and proceeds downward regardless of numeric value.
Final Answer:
2 1 2 0 1 2
Discussion & Comments