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

}

In the above class MyArray, define a new method repeatWhole(int count) that

public class MyArray { int[] nums; int numElements; public MyArray(int[] numbers) { nums = new int[numbers.length]; for(int i=0;i= count) return; int[] new_nums = new int[count]; for(int i=0;i

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!