I am trying to reverse the order of a sub-array between the indices of start and end strictly using recursion. For example, if the subarray is 1,2,3,4 , it will become 4,3,2,1.
However, I am getting the following runtime error:
java.lang.ArrayIndexOutOfBoundsException: -1
at finalExam.reverse(finalExam.java:13)
at finalExam.reverse(finalExam.java:17)
I am not sure how to fix this problem.
Thanks.
double[] reverse (double[] a, int start, int end) {
if (start == end) {return a;}
else {
a[start] = a[end];
a[end] = a[start];}
return reverse (a, start+1, end-1);
}