JAVA PROGRAM TO REVERSE THE ARRAY ELEMENT.
Java Program to reverse the element present in the Array.
Example:-
Index no:- 0 1 2 3 4 5 6
If the array is :- [76][49][73][50][93][04][27]
Index no:- 0 1 2 3 4 5 6
Then it should print:- [27][04][93][50][73][49][79]
The output is :-
Example:-
Index no:- 0 1 2 3 4 5 6
If the array is :- [76][49][73][50][93][04][27]
Index no:- 0 1 2 3 4 5 6
Then it should print:- [27][04][93][50][73][49][79]
import java.util.Scanner;
public class ReverseArray
{
public static void main(String[] args) {
int a[];
int size;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the size of the array : ");
size=sc.nextInt();
a=new int[size];
System.out.println("\nEnter "+size+" elements in the Array");
for(int i=0;i<size;i++)
a[i]=sc.nextInt();
System.out.println("Your Reverse Array is ");
int rev[]=new int[size];
for(int i=0;i<size;i++)
rev[size-i-1]=a[i];
for(int i=0;i<size;i++)
System.out.print(rev[i]+"\t");
}
}
public class ReverseArray
{
public static void main(String[] args) {
int a[];
int size;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the size of the array : ");
size=sc.nextInt();
a=new int[size];
System.out.println("\nEnter "+size+" elements in the Array");
for(int i=0;i<size;i++)
a[i]=sc.nextInt();
System.out.println("Your Reverse Array is ");
int rev[]=new int[size];
for(int i=0;i<size;i++)
rev[size-i-1]=a[i];
for(int i=0;i<size;i++)
System.out.print(rev[i]+"\t");
}
}
The output is :-
Comments
Post a Comment