Java Arrays

Java Arrays

10th - 12th Grade

11 Qs

quiz-placeholder

Similar activities

Arrays, 2D Arrays, and ArrayLists

Arrays, 2D Arrays, and ArrayLists

9th - 12th Grade

15 Qs

Single Array

Single Array

11th Grade

10 Qs

Arrays and Algorithms

Arrays and Algorithms

10th - 12th Grade

15 Qs

Area With Arrays

Area With Arrays

10th - 12th Grade

15 Qs

Programming with JavaScript: Mastery Test

Programming with JavaScript: Mastery Test

11th Grade

16 Qs

Basic Data Structures - Intro to CS

Basic Data Structures - Intro to CS

12th Grade

15 Qs

July Monthly Test IP 20.07.2020

July Monthly Test IP 20.07.2020

12th Grade

15 Qs

Java ArrayLists

Java ArrayLists

10th Grade

11 Qs

Java Arrays

Java Arrays

Assessment

Quiz

Computers

10th - 12th Grade

Medium

Created by

David Guy

Used 11+ times

FREE Resource

11 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

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

Media Image

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} ?

Media Image
Media Image
Media Image
Media Image
Media Image

3.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

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] ?

Media Image
Media Image
Media Image
Media Image
Media Image

4.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

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

Media Image

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?

Media Image
Media Image
Media Image
Media Image
Media Image

6.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

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

Media Image

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?

Media Image
Media Image
Media Image
Media Image
Media Image

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?