Answer:
public class ArrayUtils
{
//function to reverse the elements in given array
public static void reverse(String words[])
{
//find the length of the array
int n = words.length;
//iterate over the array up to the half
for(int i = 0;i < (int)(n/2);i++)
{
//swap the first element with last element and second element with second last element and so on.
String temp;
temp = words[i];
words[i] = words[n - i -1];
words[n - i - 1] = temp;
}
}
public static void main(String args[])
{
//create and array
String words[] = {"Apple", "Grapes", "Oranges", "Mangoes"};
//print the contents of the array
for(int i = 0;i < words.length;i++)
{
System.out.println(words[i]);
}
//call the function to reverse th array
reverse(words);
//print the contents after reversing
System.out.println("After reversing............");
for(int i = 0;i < words.length;i++)
{
System.out.println(words[i]);
}
}
Explanation: