Back to marketplace

Unit 8: 2D Array

No description yet. This curated deck is ready for daily study.

Total cards: 8•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (8)

#1
Front (Question)

What will int[][] grid = new int[3][4] create?

Back (Answer)

It will make a 3x4 grid of ints

#2
Front (Question)

How to get a row from your 2D int array?

Back (Answer)

int[][] grid = { {1,2,3,4}, {5,6,7,8} };

#3
Front (Question)

How do you get an element within your 2D array?

Back (Answer)

int elem = grid[1][2];

#4
Front (Question)

Consider the following code segment, which is intended to create and initialize the two-dimensional (2D) integer array num so that columns with an even index will contain only even integers and columns with an odd index will contain only odd integers. int[][] num = / missing code /; Which of the following initializer lists could replace / missing code / so that the code segment will work as intended? A. {{0, 1, 2}, {4, 5, 6}, {8, 3, 6}} B. {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}} C. {{1, 3, 5}, {2, 4, 6}, {3, 5, 7}} D. {{2, 1, 4}, {5, 2, 3}, {2, 7, 6}} E. {{2, 4, 6}, {1, 3, 5}, {6, 4, 2}}

Back (Answer)

A. {{0, 1, 2}, {4, 5, 6}, {8, 3, 6}}

#5
Front (Question)

Consider the following code segment, which is intended to display “cat”. String[][] keyboard = {{“q”, “w”, “e”, “r”, “t”}, {“a”, “s”, “d”, “f”, “g”}, {“z”, “x”, “c”, “v”, “b”}}; System.out.println(/ missing expression /); Which of the following can replace / missing expression / so that the code segment works as intended? A) keyboard[12] + keyboard[5] + keyboard[4] B) keyboard[13] + keyboard[6] + keyboard[5] C) keyboard[2][2] + keyboard[1][0] + keyboard[0][4] D) keyboard[2][2] + keyboard[0][1] + keyboard[4][0] E) keyboard[3][3] + keyboard[2][1] + keyboard[1][5]

Back (Answer)

C) keyboard[2][2] + keyboard[1][0] + keyboard[0][4]

#6
Front (Question)

How do you declare a 2D array?

Back (Answer)

datatype[][] variableName = new datatype[numberRows][numberCols];

#7
Front (Question)

How can you traverse through arrays though a tested for loop?

Back (Answer)

A for loop inside of another for loop. These are used to loop through all the elements in a 2d array. One loop can work through the rows and the other the columns.

#8
Front (Question)

How can you get an out of bounds error when traversing through an array?

Back (Answer)

This happens when a loop goes beyond the last valid index in an array. Remember that the last valid row index is arr.length - 1. The last valid column index is arr[0].length - 1.