Completing this problem too?

here is a second problem I don’t know how to solve, any solutions?

Complete the following method. Given an array of ints, return an array with all the same elements but in reverse order.

public int[] reverse(int[] nums)

Examples:
reverse([1,3,5,4]) --> [4,5,3,1]
reverse([2,2,9]) --> [9,2,2]
reverse([10]) --> [10]

Again, you will need to look at each element in your input list in order.

This time you will also need an output list that your function returns.

How long is the output list?

What is the index of the last item in the output list? How about the second to last? Third to last?

Again, work out how you, as a person, would do this. Come up with a simple list of directions that describes the process. Only after you understand how you would solve it should you start writing code.

2 Likes