logo CodeStepByStep logo

kCopies

Language/Type: Java ArrayList Collections
Related Links:

Write a method named kCopies that accepts an ArrayList of integers as a parameter and replaces every integer of value k with k copies of itself. For example, if the list stores [4, 1, 2, 0, 3] before the method is called, it should store [4, 4, 4, 4, 1, 2, 2, 3, 3, 3] after the method finishes executing. Zeroes and negative numbers should be removed from the list.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.