Search Header Logo

Java Arrays

Authored by David Guy

Computers

10th - 12th Grade

Used 11+ times

Java Arrays
AI

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

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

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?