Question: I was trying to use this recursive method to write an array backward but not sure what I'm doing wrong, any help would be appreciated

I was trying to use this recursive method to write an array backward but not sure what I'm doing wrong, any help would be appreciated

import java.util.*;

public class PrintArrayBackwards

{ private static int temp = 0;

public static void main(String[] args)

{ // TODO Auto-generated method stub

int arr[]= {1,3,6, 9, 13, 15};

backward(arr,0,5); }

static void backward(int arr[],int first, int last)

{temp = arr[first];

arr[first]=arr[last];

arr[last]=temp;

if (first>=last)

System.out.println(arr);

else

backward(arr,first+1, last-1);

}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!