The following java program gets ‘n’ numbers from user and prints the same in reverse order using array.
import java.io.*;
class PrintNReverse
{
int n;
int a[];
BufferedReader br;
void get()throws Exception
{
System.out.println("Enter n");
br=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(br.readLine());
a=new int[n];
}
void pro()throws Exception
{
for(int i=0;i<n;i++)
{
System.out.println("Enter"+(i+1)+"element");
a[i]=Integer.parseInt(br.readLine());
}
}
void show()
{
for(int i=n-1;i>=0;i--)
System.out.println(a[i]);
}
}
class PrintNReverseMain
{
public static void main(String arg[])throws Exception
{
PrintNReverse obj=new PrintNReverse();
obj.get();
obj.pro();
obj.show();
}
}