-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSol.java
More file actions
34 lines (27 loc) · 858 Bytes
/
Copy pathSol.java
File metadata and controls
34 lines (27 loc) · 858 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
32
33
34
import java.util.*;
class Sol{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Input numbers seperated by space");
String sin = sc.nextLine();
String arr[] = sin.trim().split(" ");
int intArr[] = new int[arr.length];
int i = 0;
for (String s : arr){
intArr[i] = Integer.parseInt(s);
i++;
}
int res[] = reverseArray(intArr);
for (int r : res)
System.out.print(r + " ");
}
private static int[] reverseArray(int[] intArr) {
int m = intArr.length /2 ;
for (int i = 0; i <= m ; i++){
int temp = intArr[i];
intArr[i] = intArr[intArr.length - i - 1];
intArr[intArr.length - i - 1] = temp;
}
return intArr;
}
}