Question: In the above class MyArray, define a new method repeatWhole(int count) that directly make change to the MyArray object by repeating its entire elements without
In the above class MyArray, define a new method repeatWhole(int count) that directly make change to the MyArray object by repeating its entire elements without returning anything. For example, suppose it has {10,20,30,40}. Then repeatWhole(3) makes it have {10,20,30,40,10,20,30,40,10,20,30,40}. Hint: Use of ensureCapacity() will be helpful and additional for-loop may be necessary to handle the 'count' parameter in repeatWhole(int count).
Do NOT use any other methods of MyArray except the ones defined above or any external package such as Java ArrayList.
Your answer should include method head as well as body part. eg) returnType functionName(arguments) // head part {
// body part
}

public class MyArray { int[] nums; int numElements; public MyArray(int[] numbers) { nums = new int[numbers.length]; for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
