
Java Arrays Quiz Review
Authored by David Guy
Computers
9th - 10th Grade
Used 17+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following code segment, which is intended to print the sum of all elements of an array. A runtime error occurs when the code segment is executed. Which of the following changes should be made so that the code segment works as intended?
The for loop header should be replaced with for (int k = 0; k < arr.length; k++).
The for loop header should be replaced with for (int k = 0; k <= arr.length; k--).
The for loop header should be replaced with for (int k = 1; k <= arr.length - 1; k++).
The statement in the body of the for loop should be replaced with sum += arr[0].
The statement in the body of the for loop should be replaced with sum += arr[k - 1].
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
The method countTarget below is intended to return the number of times the value target appears in the array arr. The method may not work as intended. Which of the following changes, if any, can be made to line 4 so that the method will work as intended?
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following method. Which of the following code segments, if any, can be used to replace the body of the method so that numbers will contain the same values?
I only
I and III only
II and III only
I, II, and III
None of the code segments will return an equivalent result.
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following two methods that appear within a single class. What is printed as a result of the call start()?
0 0 0 0 0 0
0 0 0 0 0 6
1 2 3 4 5 6
1 2 3 4 5 0
changeIt will throw an exception.
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider an integer array nums, which has been properly declared and initialized with one or more values. Which of the following code segments counts the number of negative values found in nums and stores the count in counter ?
I only
II only
I and II only
I and III only
I and III only
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following method, which is intended to return the number of local maximum values in an array. Local maximum values are array elements that are greater than both adjacent array elements. The first and last elements of an array have only a single adjacent element, so neither the first nor the last array element is counted by this method. For example, an array containing the values {3, 9, 7, 4, 10, 12, 3, 8} has two local maximum values: 9 and 12. Which of the following can replace /* missing loop header */ so the method countPeaks works as intended?
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following code segment:
What is printed as a result of executing the following code segment?
0
8
18
32
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?