X471: Truncate Generic Array

For this question you will be writing a method reverse that takes in two parameters.

public T[] truncate(T[] arr, T[] truncatedArr)

The variable arr will be an array of items of type T. The variable truncatedArr will be an empty array of type T. It will always have a length of 5.

For this assignment, populate truncatedArr with the first five items from arr

For example, if:

int[] a = {1, 4, 9, 23, 6, 77};
int[] b = new int[5];

calling truncate(a, b) should return an array of {1, 4, 9, 23, 6}

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.