Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created April 28, 2021 11:28
Show Gist options
  • Select an option

  • Save syedjafer/b09b93246b2b5abf1b7329947a28873d to your computer and use it in GitHub Desktop.

Select an option

Save syedjafer/b09b93246b2b5abf1b7329947a28873d to your computer and use it in GitHub Desktop.
public class ReverseNum{
static void rvereseArray(int arr[], int start, int end)
{
int temp;
if (start >= end)
return;
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
rvereseArray(arr, start+1, end-1);
}
static void printArray(int arr[], int size)
{
for (int i=0; i < size; i++)
System.out.print(arr[i] + " ");
System.out.println("");
}
public static void main (String[] args) {
int arr[] = {1, 2, 3, 4, 5, 6};
printArray(arr, 6);
rvereseArray(arr, 0, 5);
System.out.println("Reversed array is ");
printArray(arr, 6);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment