1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
viktelen [127]
3 years ago
6

Write a method manyStrings that takes an ArrayList of Strings and an integer n as parameters and that replaces every String in t

he original list with n of that String. For example, suppose that an ArrayList called "list" contains the following values:("squid", "octopus")And you make the following call:manyStrings(list, 2);Then list should store the following values after the call:("squid", "squid", "octopus", "octopus")As another example, suppose that list contains the following:("a", "a", "b", "c")and you make the following call:manyStrings(list, 3);Then list should store the following values after the call:("a", "a", "a", "a", "a", "a", "b", "b", "b", "c", "c", "c")You may assume that the ArrayList you are passed contains only Strings and that the integer n is greater than 0.
Computers and Technology
1 answer:
raketka [301]3 years ago
3 0

Answer:

public static ArrayList manyStrings(ArrayList<String> list, int n){

    ArrayList<String> newList = new ArrayList<String>();

    for (int i=0; i<list.size(); i++) {

        for (int j=0; j<n; j++) {

            newList.add(list.get(i));

        }

    }

    return newList;

}

Explanation:

Create a method called manyStrings that takes two parameters, list and n

Create a new ArrayList that will hold new values

Create a nested for loop. The outer loop iterates through the list. The inner loop adds the elements, n of this element, to the newList.

When the loops are done, return the newList

You might be interested in
Which folder does the ipad saves my pictures?
saw5 [17]
It will save it in the pre-installed iphotos application.
Hope this helps. <span />
4 0
3 years ago
Read 2 more answers
What is the first and last value of i to be displayed by the following code snippet? int n = 20; for (int i = 0; i &lt;= n; i++)
frutty [35]

Answer:

The first value of i is 0 and last value of i is 20.

Explanation:

The following are the description of a given loop.

  • In this problem, there are two loops one is the internal loop and the other is the external loop
  • In the outer loop, the value of " i" is initialized with "0" So the first value is printed 0 in the console.
  • For one value of "i" all the inner loop is executed.
  • The loop is executed is less equal to 20 that's why the last value of "i" is printed 20 in the console window.

6 0
3 years ago
A merge is _____.
Aliun [14]
The process of combining information from a variety of sources
7 0
3 years ago
Read 2 more answers
Assignment 2: room area <br>programming python in Project Stem​
White raven [17]

Answer:I love Python, very useful

Explanation:python is very easy and user friendly!

8 0
3 years ago
Edhesive 7.2 code practice Write a function named ilovepython that prints out I love Python three times. Then, call that functio
Marysya12 [62]

Answer:

def i_love_python():

   for _ in range(3):

       print("I love Python")

i_love_python()

Explanation:

3 0
3 years ago
Other questions:
  • What is the single most important component of a computer? Central Processing Unit DIP Motherboard Chipset
    8·1 answer
  • Which of the following is NOT considered a step in the problem solving process. A Try B Discover C Prepare D Define
    12·1 answer
  • A school at which you are likely to be accepted because you meet graduation requirements is called a:
    5·1 answer
  • It is a good idea to include your teacher’s name on a title page.
    12·2 answers
  • In creating a professional action plan it's important to
    12·1 answer
  • How to write email abut new home your friend ​
    14·1 answer
  • What is an information technology? ​
    12·2 answers
  • Consider the following import statement in Python, where statsmodels module is called in order to use the proportions_ztest meth
    10·1 answer
  • A maxillary partial denture will have a ____ connector, and the mandibular partial denture will have a ____ connector.
    15·1 answer
  • Assignment 1:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!