programme to print an array in reverse order in java code example

Example 1: reverse array in java

int length = array.length;
		for(int i=0;i<length/2;i++) {
			int swap = array[i];
			array[i] = array[length-i-1];
			array[length-i-1] = swap;
		}
or
Collections.reverse(Arrays.asList(array));

Example 2: how to print array backwards

var array = ['a','b','c','d','e','f','g']
var j = array.length 

for(var i = 0; i < array.length ; i++){
    console.log(array[j])
    j=j-1 }

    /*

var j holds value of the array's number of values so every time in the loop it decrements by 1 making the 
function print a backwars array



    */