Recursion is used in Java to reverse an array.

Started by Mobo01, December 02, 2022, 01:03:35 AM

Previous topic - Next topic


I'm just getting started with recursion, but I was able to utilize it to construct a basic factorial program without any difficulty. I'm now attempting to construct a recursive function that writes an array in reverse order, but I'm not sure what I'm doing wrong. I'm following the advice in this">article. I'm not sure what I'm missing. Thank you very much.

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)
     reverseDisplay(ary, position - 1);