I am just starting to learn recursion and was able to use it write a simple factorial program without much of a problem. Now I am trying to write a recursive method that writes an array in reverse order but I can't figure out what I'm doing wrong. What am I missing? Thank you.
import java.io.*;
public class Recursion {
public static void main(String[] args) throws IOException{
int myArray[] = {1,2,3,4,5,6,7,8,9,10};
}
public static void reverseDisplay(int[] ary, int position){
if(position > 0)
System.out.print(ary[position]);
reverseDisplay(ary, position - 1);
}
}
System.out.print(ary[position-1]);? The ending conditionif(position > 0)seems to suggest that.reverseDisplay, so that would be why. Could you try testing the function itself?