Difficulty: Easy
Correct Answer: An exception is thrown at runtime
Explanation:
Introduction / Context:
This item tests array indexing rules with command-line arguments. Java arrays are zero-based. Accessing an element at index length results in ArrayIndexOutOfBoundsException. Also, starting at index 1 skips the first element.
Given Data / Assumptions:
Concept / Approach:
Legal indices are 0, 1, 2. The loop attempts to access argh[3] on the final iteration, which is out of bounds, causing a runtime exception before the loop completes.
Step-by-Step Solution:
Verification / Alternative check:
Correct code would use for (int y = 0; y < x; y++) System.out.print(" " + argh[y]); which prints “ 1 2 3”.
Why Other Options Are Wrong:
Common Pitfalls:
Off-by-one errors are a classic source of runtime faults when iterating arrays with inclusive bounds.
Final Answer:
An exception is thrown at runtime
Discussion & Comments