Home >>Java Programs >Java Program to print the elements of an array in reverse order
In this program, we will create a java program to print the elements of the array in reverse order that means the last element of the array should be displayed first, followed by second last element and so on.
Program:
public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("Original array: ");
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("Array in reverse order: ");
for (int i = arr.length-1; i >= 0; i--)
{
System.out.print(arr[i] + " ");
}
}
}