-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversedArray.java
More file actions
26 lines (22 loc) · 801 Bytes
/
Copy pathReversedArray.java
File metadata and controls
26 lines (22 loc) · 801 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
package prepare;
import java.util.ArrayList;
// import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class ReversedArray {
public static void main(String[] args) {
System.out.println("Enter the size of array : ");
try (Scanner s = new Scanner(System.in)) {
int size = s.nextInt();
System.out.println("Entering the elements : ");
List<Integer> arr = new ArrayList<>();
for (int i = 0; i < size; i++) {
arr.add(i, s.nextInt());
}
System.out.println(arr);
// reverse this array by using the built in function
List<Integer> newArr = arr.reversed();
System.out.println("The reversed array is : " + newArr);
}
}
}