JAVA PROGRAM TO READ N ELEMENTS AND PRINT IN REVERSE ORDER

import java.io.*;
import java.util.*;
public class reverse{

public static void main(String[] args)
{

int asize,i;

Scanner in =new Scanner(System.in);

System.out.println("Enter the array size");
asize=in.nextInt();

int a[]=new int[asize];

System.out.println("Enter   "+asize+"   elements");

for(i=0;i<asize;i++)
a[i]=in.nextInt();

System.out.println("Given Elements are");

for(i=0;i<asize;i++)
System.out.print(a[i]+"\t");

System.out.println();


System.out.println("Elements in Reverse order :");

for(i=asize-1;i>=0;i--)
System.out.print(a[i]+"\t");

System.out.println();
}
}

OUTPUT:


No comments:

Post a Comment