MCQ Single Best Answer Moderate

Q
[Arrays]

Assume the following two-dimensional array:
int[][] x = { {8,9}, {5,6,7}, {1,2,3,4} };
What are x[0].length, x[1].length, and x[2].length ?

ID: #24939 Competency focused Practice Questions ISC Class XII Computer Science 4 views
Question Info
#24939Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 2, 3 and 3
  • B 2, 3 and 4
  • C 3, 3 and 3
  • D 2, 2 and 2
Correct Answer: Option B

Explanation

[Arrays]

Assume the following two-dimensional array:
int[][] x = { {8,9}, {5,6,7}, {1,2,3,4} };
What are x[0].length, x[1].length, and x[2].length ?
(a) 2, 3 and 3
(b) 2, 3 and 4
(c) 3, 3 and 3
(d) 2, 2 and 2
Correct Answer: (b) 2, 3 and 4

Explanation:

A two-dimensional array in Java is actually an array of arrays. Each row can have a different number of elements. Such arrays are called Jagged Arrays or Ragged Arrays.

Given Array:

int[][] x = { {8,9}, {5,6,7}, {1,2,3,4} };
Array Row Elements Length
x[0] {8,9} 2
x[1] {5,6,7} 3
x[2] {1,2,3,4} 4

Step-by-Step Understanding:

  • x[0] contains two elements: 8 and 9 → Length = 2
  • x[1] contains three elements: 5, 6 and 7 → Length = 3
  • x[2] contains four elements: 1, 2, 3 and 4 → Length = 4

Conclusion:

Therefore:

x[0].length = 2
x[1].length = 3
x[2].length = 4

So, the correct answer is: (b) 2, 3 and 4

Share This Question

Challenge a friend or share with your study group.