Array-ArrayLIst MCQ
Array-ArrayLIst MCQ
Worksheets Name
1. Consider the following method, count, which is intended to traverse all the elements in the two-
dimensional (2D) String array things and return the total number of elements that contain at least one
"a".
For example, if things contains {{"salad", "soup"}, {"water", "coffee"}}, then count(things) should return 2.
The method does not always work as intended. For which of the following two-dimensional array input
values does count NOT work as intended?
c) {{"rabbit", "bird"}, {"cat", "dog"}, {"gecko", d) {{"scarf", "gloves", "hat"}, {"shoes", "shirt",
"turtle"}} "pants"}}
[Link] 1/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
2. Consider the following method, which is intended to return the element of a 2-dimensional array that is
closest in value to a specified number, val.
/* @return the element of 2-dimensional array mat whose value is closest to val /
public double findCloset(double[][] mat, double val)
{
double answer = mat[0][0];
double minDiff = [Link](answer - val);
for (double[] row : mat)
{
for (double num : row)
{
answer = num;
minDiff = [Link](num - val);
}
}
}
return answer;
}
Which of the following could be used to replace / missing / so that findClosest will work as intended?
[Link] 2/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
{{0, 0, 3},
{0, 0, 0},
{7, 0, 0}}
Which of the following code segments can be used to correctly create and initialize myArray?
I.
int myArray[][] = new int[3 [3];
myArray[0][2] = 3;
myArray[2][0] = 7;
II.
int myArray[][] = new int[3][3];myArray[0][2] = 7;myArray[2][0] = 3;
III.
int myArray[][] = {{0, 0, 3}, {0, 0, 0}, {7, 0, 0}};
a) I only b) II only
e) II and III
[Link] 3/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
e) {{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3}}
[Link] 4/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 10 15 20 25 b) 10 20
50 55 60 65 30 40
50 60
[Link] 5/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
As a result of executing the code segment, how many times are "Condition one" and "Condition two"
printed?
a) "Condition one" is printed twice, and "Condition b) "Condition one" is printed twice, and "Condition
two" is printed twice. two" is printed once.
c) "Condition one" is printed once, and "Condition d) "Condition one" is printed once, and "Condition
two" is printed twice. two" is printed once.
[Link] 6/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 15 14 b) 15 14 13 12
25 24 23 25 24 23
35 34 33 32 35 34
45 44 43 42 41 45
c) 11 12 13 14 15 d) 15 14 13 12 11
21 22 23 24 25 24 23 22
31 32 33 35 34 33
41 42 45 44
e) 15 14 13 12 11
25 24 23 22 21
35 34 33 32 31
45 44 43 42 41
[Link] 7/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
8. Consider the following Util class, which contains two methods. The completed sum1D method returns
the sum of all the elements of the 1-dimensional array a. The incomplete sum2D method is intended to
return the sum of all the elements of the 2-dimensional array m.
Assume that sum1D works correctly. Which of the following can replace /missing code/ so that the
sum2D method works correctly?
I. for (int k = 0; k < [Link]; k++)
{
sum += sum1D(m[k]);
}
[Link] 8/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) I only b) II only
9. Consider the following code segment, where nums is a two-dimensional (2D) array of integers. The
code segment is intended to print "test1234".
[Link]("test" + nums[0][0] + nums[1][0] + nums[1][1] + nums[0][1]);
Which of the following code segments properly declares and initializes nums so that the code segment
works as intended?
a) int[][] nums = {{1, 2}, {3, 4}}; b) int[][] nums = {{1, 2}, {4, 3}};
c) int[][] nums = {{1, 3}, {2, 4}}; d) int[][] nums = {{1, 4}, {2, 3}};
10. Consider the following method, sumRows, which is intended to traverse all the rows in the two-
dimensional (2D) integer array num and print the sum of all the elements in each row.
For example, if num contains {{3, 5}, {6, 8}}, then sumRows(num) should print "8 14 ".
The method does not always work as intended. For which of the following two-dimensional array input
values does sumRows NOT work as intended?
[Link] 9/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
11. Assume that a two-dimensional (2D) array arr of String objects with 3 rows and 4 columns has been
properly declared and initialized.
Which of the following can be used to print the elements in the four corner elements of arr ?
12. Consider the following code segment, where letters is a two-dimensional (2D) array that contains
possible letters. The code segment is intended to print "DIG".
String[][] letters = {{"A", "B", "C"},
{"D", "E", "F"},
{"G", "H", "I"}};
[Link]( /* missing code */ );
Which of the following could replace /* missing code */ so that the code segment works as intended?
13. Which is the correct way to construct and assign a 2D array, with 8 rows and 10 columns, to the
variable popcorn?
[Link] 10/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) A E I b) B F J
FJ CGK
K DHL
c) E I d) F G H
FJ JKL
GK
HL
e) F J
GK
HL
[Link] 11/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
Which of the following best describes what is returned by the calculate method?
Select one:
a) The largest value in the two-dimensional array b) The smallest value in the two-dimensional
array
c) The row index of an element with the largest d) The row index of an element with the smallest
value in the two-dimensional array value in the two-dimensional array
[Link] 12/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) for (int j : arr){ for (int k : j) { [Link](j + b) for (int j : arr){ for (int k : j) { [Link](k
" "); }} + " "); }}
c) for (int[] j : arr){ for (int k : j) { [Link](j d) for (int[] j : arr){ for (int k : j) { [Link](k
+ " "); }} + " "); }}
[Link] 13/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 3 b) 4
c) 5 d) 7
e) 8
a) {6, 4, 2, 4} b) {1, 6, 3, 4}
c) {4, 3, 6, 1} d) {4, 4, 2, 2}
e) {2, 2, 4, 4}
[Link] 14/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 4 1 3 4 2 b) 4 1 3 4 2
48342 41342
48642 41342
48622 41342
48623 41342
c) 4 1 3 4 2 d) 4 4 4 4 4
41342 11111
18753 77777
74692 33333
38124 55555
e) 4 8 6 2 3
48623
48623
48623
48623
[Link] 15/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
c) for (int rc = 0; rc < [Link]; rc++) d) for (int r = 0; r < numbers[0].length; r++)
{ {
[Link](numbers[rc]); for (int c = 0; c < [Link]; c++)
} {
[Link](numbers[r][c]);
}
}
[Link] 16/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
22. Consider the following code segment, which is intended to declare and initialize the two-dimensional
(2D) String array things.
/* missing code */ = {{"spices", "garlic", "onion", "pepper"},
{"clothing", "hat", "scarf", "gloves"},
{"plants", "tree", "bush", "flower"},
{"vehicles", "car", "boat", "airplane"}};
Which of the following could replace /* missing code */ so that things is properly declared?
e) [][]String things
a) checkIndexes(table, 4, 5) b) checkIndexes(table, 4, 6)
c) checkIndexes(table, 5, 4) d) checkIndexes(table, 5, 6)
e) checkIndexes(table, 6, 5)
[Link] 17/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
Which of the following represents board after this code segment is executed?
Select one:
a) x o x o x b) o x o x o
oxoxo xoxox
xoxox oxoxo
oxoxo xoxox
xoxox xoxox
c) x o o o x d) o x o o o
oxoxo ooxoo
ooxoo
x o o keys
Answer x o are added in the last page
oxoxo oxoox
xooox ooxoo
[Link] 18/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
e) o x o x o
xoxoo
oxooo
xoooo
ooooo
25. Consider the following method, which is intended to return true if 0 is found in its two-dimensional array
parameter arr and false otherwise. The method does not work as intended.
Which of the following values of arr could be used to show that the method does not work as intended?
a) {{30, 20}, {10, 0}} b) {{4, 3}, {2, 1}, {0, -1}}
c) {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}} d) {{5, 10, 15, 20}, {25, 30, 35, 40}}
[Link] 19/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 6 b) 8
c) 13 d) 15
e) 20
[Link] 20/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
27. Consider the following code segment, where num is a properly declared and initialized integer variable.
The code segment is intended to traverse a two-dimensional (2D) array arr looking for a value equal to
num and then print the value. The code segment does not work as intended.
int[][] arr =
{{7, 3, 6, 4},
{9, 2, 0, 5},
{1, 4, 3, 8}};
For which of the following values of num does the code segment not work as intended?
a) num = 5 b) num = 6
c) num = 7 d) num = 8
e) num = 9
[Link] 21/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
How many times will "!" be printed when the code segment is executed?
a) 0 times b) 2 times
c) 4 times d) 6 times
e) 8 times
[Link] 22/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
Consider the following code segment, where all elements in data have been initialized.
How many times is the println method called when the code segment is executed?
a) 4 b) 5
c) 9 d) 10
e) 15
[Link] 23/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
How many times will the statement [Link](x + " ") be executed?
a) 3 times b) 4 times
c) 6 times d) 12 times
e) 16 times
[Link] 24/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
31. Consider the following code segment, where num is an integer variable.
a) 14 14 b) 16 17
c) 17 16 d) 18 19
e) 19 18
[Link] 25/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
32. Consider the following code segment, where num is a properly declared and initialized integer variable.
The following code segment is intended to set foundRow and foundCol to the row and column indexes
of an array element containing num. The code segment does not work as intended.
Which of the following values for num can be used as a test case to show that the code segment does
not work as intended?
a) 12 b) 15
c) 24 d) 41
e) 43
[Link] 26/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 7 b) 17
c) 21 d) 26
e) 27
[Link] 27/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
c) Hey, it really is a pleasure to finally catch up d) Hi, it is great to get to see you again
with you all
e) it's it is it really is
[Link] 28/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 36 b) 54
c) 63 d) 68
e) 78
[Link] 29/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
a) 2 3 b) 1 2 3
6 45
7
c) 1 2 3 d) 1 4 7
56 58
9 9
e) 1 2 3
56
9
1
[Link] 30/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
Answer Keys
10. d) {{4, 1, 7}, {-10, -11, -12}} 11. d) [Link](arr[0][0] 12. d) letters[1][0] + letters[2][2]
+ arr[0][3] + arr[2][0] + + letters[2][0]
arr[2][3]);
13. b) int[][] popcorn = new 14. e) F J G K H L 15. a) boolean arr[] arr[0] arr[1]
int[8][10]; [] = new [1] = [2] =
boolean[2] true; true;
[3];
16. e) The column index of an 17. d) for (int[] j : arr){ for (int k : 18. d) 7
element with the largest j) { [Link](k + "
value in the two- "); }}
dimensional array
[Link] 31/32
2/19/26, 9:30 AM unit 8 Review csa test | Wayground
25. d) {{5, 10, 15, 20}, {25, 30, 26. e) 20 27. d) num = 8
35, 40}}
[Link] 32/32