Question: IN JAVA Exercise 1: Write a method called stutter that accepts an ArrayList of Strings and an integer k as parameters. The method replaces every

IN JAVA

Exercise 1:

Write a method called stutter that accepts an ArrayList of Strings and an integer k as parameters. The method replaces every string in the list with k copies of that string.

For example, if the list stores the values ["how", "are", "you"] before the method is called, and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you", "you", "you", "you"] after the method finishes executing.

If k is 0 or negative, the list should be empty after the call.

Exercise 2:

Write a method called interleave that accepts two ArrayLists of integers a1 and a2 as parameters and inserts the elements of a2 into a1 at alternating indexes. If the lists are of unequal length, the remaining elements of the longer list are left at the end of a1.

For example, if a1 stores [10, 20, 30] and a2 stores [4, 5, 6, 7, 8], the call of interleave(a1, a2); should change a1 to store [10, 4, 20, 5, 30, 6, 7, 8].

If a2 had stored [10, 20, 30, 40, 50] and a2 had stored [6, 7, 8], the call of interleave(a1, a2); would change a1 to store [10, 6, 20, 7, 30, 8, 40, 50].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!