
Java Arrays
Authored by David Guy
Computers
10th - 12th Grade
Used 11+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
11 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
Consider the following code segment. Which of the following represents the contents of the array arr after the code segment is executed?
{0, 1, 2, 3, 4, 5, 6}
{1, 1, 1, 1, 1, 1, 1}
{1, 1, 3, 3, 5, 5, 7}
{1, 2, 3, 4, 5, 6, 7}
{2, 2, 4, 4, 6, 6, 7}
2.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
Consider the following method. Which of the following code segments, if located in a method in the same class as changeIt, will cause the array myArray to contain {0, 5, 0, 0} ?
3.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
Assume that an array of integer values has been declared as follows and has been initialized. Which of the following code segments correctly interchanges the value of arr[0] and arr[5] ?
4.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
In the following code segment, assume that the string str has been properly declared and initialized. The code segment is intended to print the number of strings in the array animals that have str as a substring. The code segment does not work as intended. Which of the following changes should be made so the code segment works as intended?
The Boolean expression in the for loop header should be changed to i < animals.length.
The Boolean expression in the for loop header should be changed to i < animals.length - 1.
The Boolean expression in the for loop header should be changed to i < animals[i].length.
The condition in the if statement should be changed to animals[i].equals(str).
The condition in the if statement should be changed to animals[i].substring(str).
5.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
Consider the code segment below, where arr is a one-dimensional array of integers. Which of the following code segments will produce the same output as the code segment above?
6.
MULTIPLE CHOICE QUESTION
5 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].
7.
MULTIPLE CHOICE QUESTION
5 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?
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
10 questions
Intro to Windows Server 2012
Quiz
•
12th Grade
10 questions
HT3.2- Validation and Reliability
Quiz
•
8th Grade - University
15 questions
Encryption Quiz
Quiz
•
10th Grade
15 questions
Vocabulary of Computer
Quiz
•
12th Grade
10 questions
BP TIK 1
Quiz
•
10th Grade
15 questions
Asesmen Sumatif
Quiz
•
12th Grade
10 questions
Q1 M 2 - TOPIC 2 / Check your understanding
Quiz
•
10th Grade
15 questions
หน่วยที่2การสร้างมูลค่าเพิ่มให้ผลิตภัณฑ์หรือบริการ
Quiz
•
11th Grade - University
Popular Resources on Wayground
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
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade