professor-curious-logo
professor-curious-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What are the differences between rectangular and non-rectangular 2D arrays?

Rectangular: All inner arrays have the same length. Non-rectangular: Inner arrays can have different lengths.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What are the differences between rectangular and non-rectangular 2D arrays?

Rectangular: All inner arrays have the same length. Non-rectangular: Inner arrays can have different lengths.

What are the differences between using arrayName.length and arrayName[0].length?

arrayName.length: Returns the number of rows. arrayName[0].length: Returns the number of columns (for rectangular arrays).

What does the following code output? int[][] arr = {{1, 2}, {3, 4}}; System.out.println(arr[0][1]);

2

Identify the error in the following code: int[][] arr = new int[2][3]; System.out.println(arr[2][1]);

ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2 (first dimension).

What does the following code output? int[][] arr = {{1, 2, 3}, {4, 5, 6}}; System.out.println(arr.length);

2

What does the following code output? int[][] arr = {{1, 2, 3}, {4, 5, 6}}; System.out.println(arr[0].length);

3

Identify the error in the following code: int[][] arr = new int[2][]; arr[0] = {1, 2}; arr[1] = {3, 4, 5};

Missing 'new int[]' when assigning values to arr[0] and arr[1]. Should be: arr[0] = new int[] {1, 2}; arr[1] = new int[] {3, 4, 5};

What does the following code output? int[][] arr = {{1}, {2, 3}, {4, 5, 6}}; System.out.println(arr[2][1]);

5

What does the following code output? int[][] arr = new int[3][4]; System.out.println(arr[1][2]);

0

Identify the error in the following code: int[][] arr = new int[3][4]; arr[1,2] = 5;

Incorrect syntax for accessing 2D array elements. Should be arr[1][2] = 5;

What does the following code output? int[][] arr = {{1, 2}, {3, 4}}; System.out.println(arr[1][0]);

3

What does the following code output? int[][] arr = {{1, 2}, {3, 4}}; System.out.println(arr[0][0]);

1

What is a 2D array?

An array of arrays, where each element is itself an array.

What is double-index notation?

A way to access elements in a 2D array using two indices: one for the row and one for the column.

What is an outer array in the context of 2D arrays?

The main array that contains other arrays as its elements.

What is an inner array in the context of 2D arrays?

One of the arrays contained within the outer array of a 2D array.

What is a rectangular 2D array?

A 2D array where all inner arrays have the same length.

What is an ArrayIndexOutOfBoundsException?

An exception thrown when trying to access an array element with an index that is outside the valid range.

What does '0-indexed language' mean?

It means that the first element in an array has an index of 0, not 1.

What is the meaning of arrayName.length for a 2D array?

It represents the number of rows in the 2D array.

What is the meaning of arrayName[0].length for a rectangular 2D array?

It represents the number of columns in the 2D array.

Define initialization of a 2D array.

Assigning an initial value to all the elements of the array when it is declared, or shortly after.