2D Array Creation and Access MCQ Practice

Question 1 of 10

A camp kitchen allocates stew-pot counts. What text does this Java code display?

int[][] pots = new int[3][2];
System.out.print(pots[2][1]);
  1. A. 3
  2. B. 2
  3. C. 0
  4. D. null

Question 2 of 10

A cider press stores vat readings. What text does this Java code display?

int[][] vats = { {6, 1, 4}, {2, 9, 8} };
System.out.print(vats[0][2]);
  1. A. 6
  2. B. 9
  3. C. 8
  4. D. 4

Question 3 of 10

A train yard creates a 5-by-2 cargo map. Which statement is true?

int[][] cargo = new int[5][2];
  1. A. cargo.length is 2 and cargo[0].length is 5.
  2. B. cargo is an array of 5 row arrays, and each of those rows has length 2.
  3. C. Every cell starts as null.
  4. D. Later code can grow the grid by assigning cargo[0].length = 3.

Question 4 of 10

A museum display aliases the top shelf. What text does this Java code display?

int[][] crates = { {11, 12, 13}, {21, 22, 23} };
int[] top = crates[0];
System.out.print(top[1]);
  1. A. 11
  2. B. 12
  3. C. 21
  4. D. 22

Question 5 of 10

A marsh survey allocates wet/dry flags. What text does this Java code display?

boolean[][] wet = new boolean[2][3];
System.out.print(wet[0][2]);
  1. A. true
  2. B. false
  3. C. null
  4. D. 0

Question 6 of 10

An observatory allocates filter names. What text does this Java code display?

String[][] filters = new String[3][1];
System.out.print(filters[2][0]);
  1. A. null
  2. B. 0
  3. C. false
  4. D. 3

Question 7 of 10

A tide station allocates meter readings. What text does this Java code display?

double[][] meters = new double[1][3];
System.out.print(meters[0][2]);
  1. A. null
  2. B. 3.0
  3. C. 1.0
  4. D. 0.0

Question 8 of 10

A mini-golf card stores hole scores. What happens when this Java code runs?

int[][] card = { {9, 8}, {7, 6} };
System.out.print(card[0][2]);
  1. A. 8 is displayed
  2. B. 6 is displayed
  3. C. 0 is displayed
  4. D. An ArrayIndexOutOfBoundsException is thrown

Question 9 of 10

A firefly lab overwrites one jar count. What text does this Java code display?

int[][] jars = { {1, 2}, {3, 4} };
jars[1][0] = 7;
System.out.print(jars[0][0] + "," + jars[1][0]);
  1. A. 1,7
  2. B. 7,7
  3. C. 1,3
  4. D. 3,7

Question 10 of 10

A solar-garden planner stores panel watts. The table shows the contents of watts. Which access reads the 18?

row Column 0 Column 1 Column 2
Row 0 11 18 7
Row 1 4 22 9
Row 2 15 3 6
int[][] watts = { {11, 18, 7}, {4, 22, 9}, {15, 3, 6} };
  1. A. watts[0][0]
  2. B. watts[1][1]
  3. C. watts[0][1]
  4. D. watts[1][0]