Respuesta :
Answer:
The sample output is below.
The code is attached.
Explanation:
Sample Output:
Original array is: 1 2 457 4 Reversed array is: 4754 2 1
Code to copy:
import java.io.*;
class Main
{
/*Define the function revArray passing the array
and its indices.*/
static void revArray(int arr[], int start, int end)
{
/*Declare an integer variable to store the
first index.*/
int temp;
//Check if array is empty.
if (start >= end)
return;
//Store the first index value.
temp = arr[start];
//Swap the last index to first index.
arr[start] = arr[end];
//Store the temp value to last index.
arr[end] = temp;
/*Call the function recursively to swap
rest of the values.*/
revArray(arr, start+1, end-1);
}
public static void main (String[] args)
{
//Declare and initialize array.
int[] arr = {1,2,4,5,7,4};
/*Declare an integer variable to store the
* length of array.
*/
int count=0;
//Set the length of array to count.
for(int i=0;i<arr.length;i++)
count++;
System.out.println("Original array is:");
///Print the original array.
for(int i=0; i<count;i++)
{
System.out.print(arr[i]+" ");
}
/*Call the function to reverse the values in
* the array itself.
*/
revArray(arr, 0, count-1);
System.out.println("\nReversed array is:");
///Print the reversed array.
for(int i=0; i<count;i++)
{
System.out.print(arr[i]+" ");
}
}
}
![Ver imagen femotinga](https://us-static.z-dn.net/files/daa/ebea635ef325aa947d966f4e43362250.png)
![Ver imagen femotinga](https://us-static.z-dn.net/files/d4c/1494c1e3162b4cd0b765ed9caf9745f8.png)
![Ver imagen femotinga](https://us-static.z-dn.net/files/d5d/51b549c1e8780df14a802a0046242986.png)
![Ver imagen femotinga](https://us-static.z-dn.net/files/d6f/b4361ab71be27f4259e5c61a0002aecc.png)