Do the following program based on array
3)To input n elements into an array and display it in reverse order.
Answers
Answered by
0
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n;
System.out.println("Enter the size of the array:);
n=in.nextInt();
int a[]=new int [n];
System.out.println("Enter the elements of the array:");
for(int i=0;i<5;i++)
{
a[i]=in.nextInt();
}
System.out.println("Given Array:"+Arrays.toString(a));
System.out.println("The reversed array:");
for(int i=4;i>=0;i--)
{
System.out.print(a[i]+" ");
}
}
}
Attachments:
Similar questions