Difficulty: Easy
Correct Answer: int[][] scores = {2,7,6}, {9,3,45};
Explanation:
Introduction / Context:
Two-dimensional array initialization in Java requires proper nesting of braces to form rows. This question focuses on identifying the malformed declaration among otherwise valid array declarations.
Given Data / Assumptions:
Concept / Approach:
A two-dimensional array literal uses nested braces: new int[][] { {row1}, {row2} }
or simply { {row1}, {row2} }
when used with a declaration. Flat lists without nested braces are illegal for 2D arrays.
Step-by-Step Solution:
Verification / Alternative check:
Correct form for B would be int[][] scores = { {2,7,6}, {9,3,45} };
Why Other Options Are Wrong:
They all follow legal Java syntax for array declarations and initializations.
Common Pitfalls:
Forgetting inner braces for multi-dimensional initializers; mixing up new int[] { ... }
versus size-based creation.
Final Answer:
int[][] scores = {2,7,6}, {9,3,45};
Discussion & Comments