newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Mobo01 on December 02, 2022, 01:03:35 AM

Title: Recursion is used in Java to reverse an array.
Post by: Mobo01 on December 02, 2022, 01:03:35 AM
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 (//https). I'm not sure what I'm missing. Thank you very much.
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);
  }
}