Question: //Need help with getting this function to work //trying to reverse numbers in an int [] array recursively and then returning and printing new int

//Need help with getting this function to work

//trying to reverse numbers in an int [] array recursively and then returning and printing new int [] from main()

public class ReversalArray

{ public static int Reversal(int [] data, int low , int high) { if (low < high) { int temp= data[low]; data[low]= data[high]; data[high]= temp; Reversal(data, (low+1), (high-1)); } //return Reversal(data, (low+1), (high-1)); } public static void main(String[] args) { System.out.println("Please enter starting index : "); Scanner tool = new Scanner(System.in); int StartingIndex= tool.nextInt(); System.out.println("Please enter ending index : "); int EndingIndex= tool.nextInt(); int [] data= {4,3,6,2,8,9,5}; int result= Reversal(data, StartingIndex, EndingIndex); //System.out.printf("Up to index %d (including the number at index %d) sum is %d", index, index, result); tool.close();

} }

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!