Reverse of array elements



CODE:
import java.util.*;
class Reverse
{
     public static void main(String args[])
     {
           int i,n;
           Scanner sc = new Scanner(System.in);
           System.out.println("Enter number of elements:");
           n=sc.nextInt();
           int a[]=new int[n];
           int b[]=new int[n];
           for(i=0;i<=n-1;i++)
           {
                System.out.print("enter a no:");
                a[i]=sc.nextInt();
           }
           for(i=0;i<=n-1;i++)
           {
                b[n-i-1]=a[i];
           }
           for(i=0;i<=n-1;i++)
           {
                System.out.println(b[i]);
           }
     }
}
OUTPUT:
    

No comments :

Post a Comment