Question: Write code in Java. write a function fill with signature. int[] fill(int[] arr, int k, int n) Which does the following : it returns an

Write code in Java.

write a function fill with signature.

int[] fill(int[] arr, int k, int n)

Which does the following : it returns an integer array arr2 of length n whose first k elements are the same as the first k elements of arr, and whose remaining elements consist of repeating blocks of the first k elements . you can assume array arr has at least k elements . the function should return null if either k or n is not positive .

Examples: fill {{1,2,3,5,9,12,-2,-1},3,10} returns{ 1,2,3,1,2,3,1,2,3,1}. fill{{ 4,2,-3,12},1,5} return{4,4,4,4,4}. fill{2,6,9,0,-3},0,4} return null.

please explain your answer.

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!