Program to reverse an array in java

Let’s see a┬áprogram to reverse an array in java.

 

package failfastandfailsafe;

import java.util.Scanner;

public class Example {
	public static void reverseOfArray(int[] arr) {
		for (int i = arr.length - 1; i > 0; i--) {

			System.out.println(arr[i]);
		}
	}

	public static void main(String[] args) {
		int a[] = { 5, 4, 8, 7, 9, 2, 1 };
		reverseOfArray(a);

	}
}

Output is :-


1
2
9
7
8
4