Given the declaration int[][] scores = {{84, 91, 76}, {88, 95, 82}, {79, 86, 90}};, what value is stored in scores[2][1]?
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.
True or false: After int[][] values = new int[2][3]; executes, every element of values is initialized to 0.
- A
True
- B
False
How many rows are in int[][] table = {{4, 7}, {2, 9}, {6, 1}};? Enter the number of rows as a whole number.
Complete each statement about arrays created with new: an uninitialized int element has the value , while an uninitialized String element has the value .
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.
- A
7 4 2 5 9 1
- B
7 2 4 9 5 1
- C
7 2 9 4 5 1
- D
7 9 2 4 1 5
Which statements correctly describe a column-major traversal of a rectangular two-dimensional array? Select all correct statements.
- A
The outer loop can control the column.
- B
The first index in
grid[row][col]identifies the column. - C
The inner loop can control the row.
- D
For a rectangular grid, the column loop can use
grid[0].lengthas its limit.
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.
- A
True
- B
False
How many horizontal increases does countHorizontalIncreases report for int[][] data = {{3, 1, 4}, {5, 8, 6}}? Enter the count as a whole number.
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.
Which implementation strategy correctly shifts one row of a two-dimensional array one position to the right, wrapping the last element to the front?
- A
Save the last element, then copy from right to left, and put the saved value at column 0.
- B
Save the first element, then copy from left to right, and put the saved value at the last column.
- C
Copy from left to right without temporary storage.
- D
Copy from right to left but discard the original last element.
Which two statements correctly describe the index behavior of methods that sum one row or one column? Select all that apply.
- A
To sum a row, keep the row index fixed while changing the column index.
- B
To sum a row, keep the column index fixed while changing the row index.
- C
To sum a column, change both indexes on every iteration.
- D
To sum a column, keep the column index fixed while changing the row index.
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.
- A
True
- B
False
What value does columnSum(data, 1) return for int[][] data = {{3, 2, 9}, {4, 5, 1}, {7, 8, 6}};?
- A
9
- B
12
- C
14
- D
15
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.
True or false: In Java, a two-dimensional array is an array of arrays.
- A
True
- B
False
Given the Java array below, which value is returned by scores[2][1]?
int[][] scores = {{84, 91, 76}, {88, 95, 82}, {79, 86, 90}};
- A
84
- B
86
- C
90
- D
76
For int[][] grid = {{4, 7}, {1, 9}, {6, 2}};, what is the value of grid.length?
True or false: After int[][] values = new int[3][4];, every element initially contains 0.
- A
True
- B
False
A row-major traversal processes the array below. Which sequence is printed?
int[][] grid = {{1, 2, 3}, {4, 5, 6}};
- A
1, 4, 2, 5, 3, 6
- B
1, 2, 3, 4, 5, 6
- C
3, 2, 1, 6, 5, 4
- D
1, 2, 4, 5, 3, 6
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?
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.
- A
The outer loop should use
row < data.length. - B
The inner loop should use
col < data[row].length - 1. - C
The comparison should use
data[row][col] < data[row + 1][col]. - D
The comparison should use `data[row][col] < data[row][col + 1].
What is the average of all elements in int[][] data = {{2, 8}, {5, 6}}? Enter the exact decimal value; no rounding is accepted.
Consider this array:
int[][] data = {{1, 3, 5, 7}, {4, 2, 8, 6}};
What does countVerticalIncreases(data) return?
- A
1
- B
3
- C
2
- D
4
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}}?
Which sequence results from column-major traversal of this rectangular array?
int[][] grid = {{2, 4}, {5, 7}, {9, 1}};
- A
2, 5, 9, 4, 7, 1
- B
2, 4, 5, 7, 9, 1
- C
9, 5, 2, 1, 7, 4
- D
2, 5, 4, 7, 9, 1
Given int[][] data = {{4, 5, 6}, {7, 8, 9}};, which value is returned by data[1][1]?
- A
6
- B
8
- C
9
- D
10
What sequence is printed by the following row-major traversal?
int[][] grid = {{10, 20, 30}, {40, 50, 60}};
- A
10 40 20 50 30 60
- B
10 20 30 60 50 40
- C
10 20 30 40 50 60
- D
10 40 50 20 30 60
What value does average return for the array {{2, 3}, {5, 8}} when it uses the provided algorithm that returns (double) sum / count?
- A
4
- B
4.0
- C
5.0
- D
4.5
The maximum method is called with int[][] data = {{-7, -3}, {-5, -1}};. What does it return?
- A
-7
- B
-1
- C
0
- D
1
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;}
Related study packs and tools
1. Computing, Culture, and Society
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
01. Introduction to Programming and Algorithmic Problem Solving
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
3. Risks and Unintended Consequences
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
6. Cybersecurity and Digital Safety
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
7. Encryption, Privacy, and Trust
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
08 — Discrete Mathematics for Computer Science
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
9. Evaluating the Social Impact of Computing
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
12 — Foundations Capstone
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
Fault Tolerance and Redundant Systems
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
How the Internet Works
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
Packets, Links, and Network Performance
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
Parallel and Distributed Computing
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.