Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following method. public ArrayList sequence(int n) { ArrayList list = new ArrayList (); for (int k = 0; k < n; k++) {

Consider the following method.

public ArrayList sequence(int n) { ArrayList list = new ArrayList(); for (int k = 0; k < n; k++) { list.add(new Integer(n + 2 * k)); } return list; }

Which of the following is printed as a result of executing the following statement?

System.out.println(sequence(5));

[7, 9, 11, 13]

[7, 9, 11, 13, 15]

[5, 7, 9, 11, 13]

[5, 7, 9, 11]

[0, 2, 4, 6, 8]

2.

Consider the following method:

public static void mystery(ArrayList words) { int k = 0; int newSize = 3 * words.size(); while (words.size() < newSize && words.size() > 0) { words.add(words.get(k)); k++; } } 

Which of the following describes what the method mystery() does to the ArrayList words?

The ArrayList words is extended to three times its size by repeating the entire contents of the list three times in sequence.

The ArrayList words is unchanged.

The ArrayList words is extended to three times its size by replacing each single element in the list with that element repeated three times.

The method generates an IndexOutOfBoundsException.

The ArrayList words is extended to three times its size by repeating the first element of the list at the end of the original list until the size of the list is three times its original size.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago