forked from mranjan15/Java-Code-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseArray.java
More file actions
31 lines (28 loc) · 719 Bytes
/
ReverseArray.java
File metadata and controls
31 lines (28 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
**************************** One-dimensional Arrays ****************************
****************************** Reversing an Array ******************************
*/
import java.util.Scanner;
public class ReverseArray{
public static void main(String args[]){
Scanner inp = new Scanner(System.in);
int n,i, temp;
System.out.print("Enter the size of array: ");
n = inp.nextInt();
int[] a;
a = new int[n];
System.out.println("Enter the array element:");
for(i=0; i<n; i++){
a[i] = inp.nextInt();
}
for(i=0; i<(n/2); i++){
temp = a[i];
a[i] = a[n-i-1];
a[n-i-1] = temp;
}
System.out.print("The Reversed Array is: ");
for(i=0; i<n; i++){
System.out.print(a[i]+" ");
}
}
}