-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Reverse.java
More file actions
30 lines (29 loc) · 986 Bytes
/
Array_Reverse.java
File metadata and controls
30 lines (29 loc) · 986 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
import java.util.Scanner;
public class Array_Reverse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Size of Array: ");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.print("Enter the elements of the Array: ");
System.out.print("Original Array: ");
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int first = 0;
int last = arr.length - 1;
while(first<last){
int temp = arr[first];
arr[first] = arr[last];
arr[last] = temp;
first++;
last--;
}
System.out.println();
System.out.print("Reversed Array: ");
// Traversing through the reversed Array to print the value of elements of the Array
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
}