-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathArraysDS.java
30 lines (25 loc) Β· 842 Bytes
/
ArraysDS.java
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
package arrays;
import java.util.Arrays;
import java.util.Scanner;
public class ArraysDS {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int length = scanner.nextInt();
int[] array = getArray(length);
System.out.println(Arrays.toString(reverse(array)));
}
private static int[] getArray(int length) {
int[] array = new int[length];
for (int index = 0 ; index < array.length ; index++) {
array[index] = scanner.nextInt();
}
return array;
}
private static int[] reverse(int[] array) {
int[] result = new int[array.length];
for (int index = 0 ; index < array.length ; index++) {
result[index] = array[array.length - 1 - index];
}
return result;
}
}