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 }
Example 2: reverse array java
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) {
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: ");
for (int i = arr.length-1; i >= 0; i--) {
System.out.print(arr[i] + " ");
}
}
}