Java, recursively reverse an array

后端 未结 13 1138
悲&欢浪女
悲&欢浪女 2020-12-17 16:44

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) {
         


        
13条回答
  •  孤城傲影
    2020-12-17 17:36

    Calling reverseArray(0, n, arr) here n is length of array

    public void reverseArray(int i, int n, int [] arr)
    {
       if(i==n)
       {
         return ;
       } 
       else
       {
         reverseArray(i+1, n, arr);
         System.out.println(arr.at(i));
       }
    }
    

提交回复
热议问题