rev_array.java
24 linesjava
DOWNLOAD
1// Aim: Program to perform Array operations (Reverse Array).
2import java.util.*;
3public class rev_array {
4    public static void main(String[] args) {
5        Scanner sc = new Scanner(System.in);
6        int arr[] = new int[30];
7        System.out.print("Enter the number of elements: ");
8        int n = sc.nextInt();
9        System.out.print("Enter the elements: ");
10        for(int i=0; i<n; i++) {
11            arr[i] = sc.nextInt();
12        }
13        System.out.println("Original array: ");
14        for(int i=0; i<n; i++) {
15            System.out.print(arr[i] + " ");
16        }
17        System.out.println();
18        System.out.println("Reversed array: ");
19        for(int i=n-1; i>=0; i--) {
20            System.out.print(arr[i] + " ");
21        }
22    }
23}
24