Free Practice Quiz Question List

Applying Java Two-Dimensional Array Algorithms Online Quiz Questions

Use this free practice quiz with 30 questions to review Applying Java Two-Dimensional Array Algorithms, test your knowledge, and prepare for your next test or exam.

30 questions
01
Choose one
1 point

Given the declaration int[][] scores = {{84, 91, 76}, {88, 95, 82}, {79, 86, 90}};, what value is stored in scores[2][1]?

  1. A

    79

  2. B

    86

  3. C

    90

  4. D

    95

02
True or false
1 point

True or false: After int[][] values = new int[2][3]; executes, every element of values is initialized to 0.

  1. A

    True

  2. B

    False

03
Written response
1 point

How many rows are in int[][] table = {{4, 7}, {2, 9}, {6, 1}};? Enter the number of rows as a whole number.

04
Fill in the blank
1 point

Complete each statement about arrays created with new: an uninitialized int element has the value , while an uninitialized String element has the value .

05
Choose one
1 point

What sequence is printed by this row-major traversal?

int[][] grid = {{7, 2, 9}, {4, 5, 1}};

The nested loops visit each row from column 0 through its last column.

  1. A

    7 4 2 5 9 1

  2. B

    7 2 4 9 5 1

  3. C

    7 2 9 4 5 1

  4. D

    7 9 2 4 1 5

06
Choose all
1 point

Which statements correctly describe a column-major traversal of a rectangular two-dimensional array? Select all correct statements.

  1. A

    The outer loop can control the column.

  2. B

    The first index in grid[row][col] identifies the column.

  3. C

    The inner loop can control the row.

  4. D

    For a rectangular grid, the column loop can use grid[0].length as its limit.

07
True or false
1 point

True or false: A method that finds the maximum of an integer two-dimensional array is always correct if it initializes max to 0 before traversing the array.

  1. A

    True

  2. B

    False

08
Written response
1 point

How many horizontal increases does countHorizontalIncreases report for int[][] data = {{3, 1, 4}, {5, 8, 6}}? Enter the count as a whole number.

09
Fill in the blank
1 point

In a method that compares data[row][col] with data[row][col + 1], the inner loop should continue while col < so that the next-column access stays in bounds.

10
Choose one
1 point

Which implementation strategy correctly shifts one row of a two-dimensional array one position to the right, wrapping the last element to the front?

  1. A

    Save the last element, then copy from right to left, and put the saved value at column 0.

  2. B

    Save the first element, then copy from left to right, and put the saved value at the last column.

  3. C

    Copy from left to right without temporary storage.

  4. D

    Copy from right to left but discard the original last element.

11
Choose all
1 point

Which two statements correctly describe the index behavior of methods that sum one row or one column? Select all that apply.

  1. A

    To sum a row, keep the row index fixed while changing the column index.

  2. B

    To sum a row, keep the column index fixed while changing the row index.

  3. C

    To sum a column, change both indexes on every iteration.

  4. D

    To sum a column, keep the column index fixed while changing the row index.

12
True or false
1 point

True or false: A row-reversal algorithm needs to process every position in the row because stopping after the two boundaries meet would leave some elements unreversed.

  1. A

    True

  2. B

    False

13
Choose one
1 point

What value does columnSum(data, 1) return for int[][] data = {{3, 2, 9}, {4, 5, 1}, {7, 8, 6}};?

  1. A

    9

  2. B

    12

  3. C

    14

  4. D

    15

14
Open ended
1 point

Write or describe a Java method that returns the maximum value in a nonempty rectangular int[][] array. Explain why your initialization remains correct when every element is negative.

15
True or false
1 point

True or false: In Java, a two-dimensional array is an array of arrays.

  1. A

    True

  2. B

    False

16
Choose one
1 point

Given the Java array below, which value is returned by scores[2][1]?

int[][] scores = {{84, 91, 76}, {88, 95, 82}, {79, 86, 90}};

  1. A

    84

  2. B

    86

  3. C

    90

  4. D

    76

17
Written response
1 point

For int[][] grid = {{4, 7}, {1, 9}, {6, 2}};, what is the value of grid.length?

18
True or false
1 point

True or false: After int[][] values = new int[3][4];, every element initially contains 0.

  1. A

    True

  2. B

    False

19
Choose one
1 point

A row-major traversal processes the array below. Which sequence is printed?

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

  1. A

    1, 4, 2, 5, 3, 6

  2. B

    1, 2, 3, 4, 5, 6

  3. C

    3, 2, 1, 6, 5, 4

  4. D

    1, 2, 4, 5, 3, 6

20
Written response
1 point

What integer does total return for int[][] data = {{2, 5, 1}, {8, 7, 7}}; when it uses a complete nested row-major traversal to sum all elements?

21
Choose all
1 point

Select all choices that are correct for implementing a method that counts horizontal increases by comparing each element with the next element in the same row.

  1. A

    The outer loop should use row < data.length.

  2. B

    The inner loop should use col < data[row].length - 1.

  3. C

    The comparison should use data[row][col] < data[row + 1][col].

  4. D

    The comparison should use `data[row][col] < data[row][col + 1].

22
Written response
1 point

What is the average of all elements in int[][] data = {{2, 8}, {5, 6}}? Enter the exact decimal value; no rounding is accepted.

23
Choose one
1 point

Consider this array:

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

What does countVerticalIncreases(data) return?

  1. A

    1

  2. B

    3

  3. C

    2

  4. D

    4

24
Written response
1 point

After reverseRow(data, 1) executes, what is the value at data[1][3] if data initially is {{1, 2, 3}, {9, 4, 6, 2, 8}}?

25
Choose one
1 point

Which sequence results from column-major traversal of this rectangular array?

int[][] grid = {{2, 4}, {5, 7}, {9, 1}};

  1. A

    2, 5, 9, 4, 7, 1

  2. B

    2, 4, 5, 7, 9, 1

  3. C

    9, 5, 2, 1, 7, 4

  4. D

    2, 5, 4, 7, 9, 1

26
Choose one
1 point

Given int[][] data = {{4, 5, 6}, {7, 8, 9}};, which value is returned by data[1][1]?

  1. A

    6

  2. B

    8

  3. C

    9

  4. D

    10

27
Choose one
1 point

What sequence is printed by the following row-major traversal?

int[][] grid = {{10, 20, 30}, {40, 50, 60}};

  1. A

    10 40 20 50 30 60

  2. B

    10 20 30 60 50 40

  3. C

    10 20 30 40 50 60

  4. D

    10 40 50 20 30 60

28
Choose one
1 point

What value does average return for the array {{2, 3}, {5, 8}} when it uses the provided algorithm that returns (double) sum / count?

  1. A

    4

  2. B

    4.0

  3. C

    5.0

  4. D

    4.5

29
Choose one
1 point

The maximum method is called with int[][] data = {{-7, -3}, {-5, -1}};. What does it return?

  1. A

    -7

  2. B

    -1

  3. C

    0

  4. D

    1

30
Fill in the blank
1 point

Complete the missing Java statement so this method returns the number of even integers in the two-dimensional array. Enter the statement including its semicolon.

public static int countEven(int[][] data) {
int count = 0;
for (int row = 0; row < data.length; row++) {
for (int col = 0; col < data[row].length; col++) {
if (data[row][col] % 2 == 0) {

}
}
}
return count;
}