6. Program to print the elements of an array in reverse
💡Code:
public class Singledimensionarray3_7078 { public static void main(String[] args) { // Example array int[] numbers = {1, 2, 3, 4, 5}; // Print elements of the array in reverse System.out.println("Elements of the array in reverse order:"); printArrayInReverse(numbers); } // Function to print elements of an array in reverse order private static void printArrayInReverse(int[] array) { for (int i = array.length - 1; i >= 0; i--) { System.out.print(array[i] + " "); } } }
📸Output :
.png)