
unit 8 Review csa test
Authored by Jeff Cougger
Computers
Professional Development
Used 5+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
36 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
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?
{{"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
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
40 questions
PTS GANJIL 2023 PKK XI
Quiz
•
Professional Development
32 questions
Révision - Couche Accès réseau et adressage
Quiz
•
Professional Development
33 questions
6 ÔT GHK 1 - TIN HỌC
Quiz
•
Professional Development
40 questions
PEMOGRAMAN BEROREANTASI OBJECK--RPL
Quiz
•
Professional Development
40 questions
Python OKKK
Quiz
•
Professional Development
38 questions
IT Basic Assesment
Quiz
•
7th Grade - Professio...
35 questions
Python Knowledge Check
Quiz
•
Professional Development
31 questions
Network-Recap
Quiz
•
Professional Development
Popular Resources on Wayground
7 questions
History of Valentine's Day
Interactive video
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
15 questions
Valentine's Day Trivia
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
44 questions
Would you rather...
Quiz
•
Professional Development
20 questions
Black History Month Trivia Game #1
Quiz
•
Professional Development
12 questions
Mardi Gras Trivia
Quiz
•
Professional Development
14 questions
Valentine's Day Trivia!
Quiz
•
Professional Development
7 questions
Copy of G5_U5_L14_22-23
Lesson
•
KG - Professional Dev...
16 questions
Parallel, Perpendicular, and Intersecting Lines
Quiz
•
KG - Professional Dev...
11 questions
NFL Football logos
Quiz
•
KG - Professional Dev...
12 questions
Valentines Day Trivia
Quiz
•
Professional Development