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".
public static int count(String[][] things)
{
int count = 0;
for (int r = 0; r < things.length; r++)
{
for (int c = 0; c < things[r].length - 1; c++)
{
if (things[r][c].indexOf("a") >= 0)
{
count++;
}
}
}
return count;
}
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?

unit 8 Review csa test

Quiz
•
Computers
•
Professional Development
•
Easy
Jeff Cougger
Used 5+ times
FREE Resource
36 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
{{"lemon"}, {"lime"}}
{{"tall", "short"}, {"up", "down"}}
{{"rabbit", "bird"}, {"cat", "dog"}, {"gecko", "turtle"}}
{{"scarf", "gloves", "hat"}, {"shoes", "shirt", "pants"}}
{{"math", "english", "physics"}, {"golf", "baseball", "soccer"}}
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
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 = Math.abs(answer - val);
for (double[] row : mat)
{
for (double num : row)
{
answer = num;
minDiff = Math.abs(num - val);
}
}
}
return answer;
}
Which of the following could be used to replace / missing / so that findClosest will work as intended?
val - row[num] < minDiff
Math.abs(num - minDIff) < minDiff
val - num < 0.0
Math.abs(num - val) < minDiff
Math.abs(row[num] - val) < minDiff
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
A two-dimensional array myArray is to be created with the following contents.
{{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}};
I only
II only
III only
I and III
II and III
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int[][] mat = new int[3][4];
for (int row = 0; row < mat.length; row++)
{
for (int col = 0; col < mat[0].length; col++)
{
if (row < col)
{
mat[row][col] = 1;
}
else if (row == col)
{
mat[row][col] = 2;
}
else
{
mat[row][col] = 3;
}
}
}
What are the contents of
mat
after the code segment has been executed?
{{2, 1, 1},
{3, 2, 1},
{3, 3, 2},
{3, 3, 3}}
{{2, 3, 3},
{1, 2, 3},
{1, 1, 2},
{1, 1, 1}}
{{2, 3, 3, 3},
{1, 2, 3, 3},
{1, 1, 2, 3}}
{{2, 1, 1, 1},
{3, 2, 1, 1},
{3, 3, 2, 1}}
{{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3}}
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int[][] mat = {{10, 15, 20, 25},
{30, 35, 40, 45},
{50, 55, 60, 65}};
for (int[] row : mat)
{
for (int j = 0; j < row.length; j += 2)
{
System.out.print(row[j] + " ");
}
System.out.println();
}
What, if anything, is printed as a result of executing the code segment?
10 15 20 25
50 55 60 65
10 20
30 40
50 60
10 15 20 35
30 35 40 45
50 55 60 65
Nothing is printed, because an ArrayIndexOutOfBoundsException is thrown.
Nothing is printed, because it is not possible to use an enhanced for loop on a two-dimensional array.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int[][] arr = {{3, 2, 1}, {4, 3, 5}};
for (int row = 0; row < arr.length; row++)
{
for (int col = 0; col < arr[row].length; col++)
{
if (col > 0)
{
if (arr[row][col] >= arr[row][col - 1])
{
System.out.println("Condition one");
}
}
if (arr[row][col] % 2 == 0)
{
System.out.println("Condition two");
}
}
}
As a result of executing the code segment, how many times are "Condition one" and "Condition two" printed?
"Condition one" is printed twice, and "Condition two" is printed twice.
"Condition one" is printed twice, and "Condition two" is printed once.
"Condition one" is printed once, and "Condition two" is printed twice.
"Condition one" is printed once, and "Condition two" is printed once.
"Condition one" is never printed, and "Condition two" is printed once.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int[][] points = {{11, 12, 13, 14, 15},
{21, 22, 23, 24, 25},
{31, 32, 33, 34, 35},
{41, 42, 43, 44, 45}};
for (int row = 0; row < points.length; row++)
{
for (int col = points[0].length - 1; col >= row; col--)
{
System.out.print(points[row][col] + " ");
}
System.out.println();
}
What is printed when this code segment is executed?
15 14
25 24 23
35 34 33 32
45 44 43 42 41
15 14 13 12
25 24 23
35 34
45
11 12 13 14 15
21 22 23 24
31 32 33
41 42
15 14 13 12 11
25 24 23 22
35 34 33
45 44
15 14 13 12 11
25 24 23 22 21
35 34 33 32 31
45 44 43 42 41
Create a free account and access millions of resources
Similar Resources on Quizizz
33 questions
Programming in C Quiz

Quiz
•
Professional Development
38 questions
s4wp

Quiz
•
Professional Development
40 questions
10.Primitive Data Types (boolean and char)

Quiz
•
Professional Development
40 questions
HTML CSS JS Teacher Assessment

Quiz
•
Professional Development
41 questions
Microsoft Excel Quiz

Quiz
•
Professional Development
41 questions
TCS NQT Mock Test 1,VERBAL ABILITY,QUANTITATIVE APTITUDE,PROGRAM

Quiz
•
Professional Development
33 questions
Chapter 4 : JavaScript Introduction

Quiz
•
Professional Development
41 questions
Git y GithHub y arrays y sus metodos

Quiz
•
Professional Development
Popular Resources on Quizizz
15 questions
Multiplication Facts

Quiz
•
4th Grade
20 questions
Math Review - Grade 6

Quiz
•
6th Grade
20 questions
math review

Quiz
•
4th Grade
5 questions
capitalization in sentences

Quiz
•
5th - 8th Grade
10 questions
Juneteenth History and Significance

Interactive video
•
5th - 8th Grade
15 questions
Adding and Subtracting Fractions

Quiz
•
5th Grade
10 questions
R2H Day One Internship Expectation Review Guidelines

Quiz
•
Professional Development
12 questions
Dividing Fractions

Quiz
•
6th Grade