Java Program to reverse an array
Answers
Answered by
2
Required Answer:
import java.util.*;
class reversearr{
public static void main (String ar[]){
Scanner sc=new Scanner (System.in);
System.out.println("Enter size of array");
int l=sc.nextInt();
int a[]=new int[l];
System.out.println("Enter "+l+" elements");
for(int I=0;I<l;I++)
a[I]=sc.nextInt();
for(int I=0,k=l-1;I<l/2;I++,k--){
int t=a[I];
a[I]=a[k];
a[k]=t;
}
System.out.println("Reverse");
for(int I=0;I<l;I++)
System.out.println(a[I]);
}
}
- Check attachment
•••♪
Attachments:
Similar questions