
Java Arrays

Quiz
•
Computers
•
10th - 12th Grade
•
Medium
David Guy
Used 11+ times
FREE Resource
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?
Create a free account and access millions of resources
Similar Resources on Wayground
16 questions
Computer Science 2.2

Quiz
•
10th Grade
15 questions
Area and Arrays

Quiz
•
10th - 12th Grade
8 questions
2D Arrays in Java (Review)

Quiz
•
12th Grade
16 questions
CSA Unit 3 Review

Quiz
•
10th - 12th Grade
15 questions
Java Basic Data Structures

Quiz
•
6th - 10th Grade
11 questions
JS Certification

Quiz
•
12th Grade
12 questions
Javascript Arrays

Quiz
•
9th - 12th Grade
15 questions
2D Lists and Arrays

Quiz
•
10th - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
20 questions
Analog vs Digital

Quiz
•
9th - 12th Grade
10 questions
CTEA Computer Vocab Terms #1

Quiz
•
12th Grade
10 questions
Exploring Cybersecurity Techniques and Threats

Interactive video
•
6th - 10th Grade
10 questions
Understanding the Internet and Data Transmission

Interactive video
•
7th - 12th Grade