I haven\'t found anything with the specific needs of my function to do this, yes, it is for homework.
So I have:
public void reverseArray(int[] x) {
Try something as below:
public void reverseArray(int[] x) {
if(x.length ==2){
//if two elements, swap them
int first = x[0];
x[0] = x[1];
x[1] = first;
}else if(x.length > 2){
//swap first and last
int first = x[0];
x[0]= x[x.length-1];
x[x.length-1] = first;
//create a copy of middle elements
int [] copy = new int[x.length-2];
System.arraycopy( x, 1, copy, 0, x.length-2);
//recursive call for middle elements
reverseArray(copy);
//place the reversed elements back in the original array
System.arraycopy( copy, 0, x, 1, copy.length);
}
}