print array in reverse order java code example

Example 1: 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



    */

Example 2: reverse array java

// reverse array

for(int i=intArray.length-1;i>=0;i--)
         System.out.print(intArray[i] + "  ");

Example 3: java code to reverse an array

public class ReverseArray {  
    public static void main(String[] args) {  
        //Initialize array  
        int [] arr = new int [] {1, 2, 3, 4, 5};  
        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: ");  
        //Loop through the array in reverse order  
        for (int i = arr.length-1; i >= 0; i--) {  
            System.out.print(arr[i] + " ");  
        }  
    }  
}