Write Method Called Stutter Accepts Arraylist Strings Integer K Parameters Replaces Every Q37100884

Write a method called stutter that accepts an ArrayList ofstrings and an integer k as parameters and that replaces everystring with k copies of that string. For example, if the liststores the values [“how”, “are”, “you?”] before the method iscalled 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, thelist should be empty after the call.


Solution


public void stutter(ArrayList<String> str, int k) { if(k <= 0) { str.clear();

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.