-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (28 loc) · 1.23 KB
/
Copy pathSolution.java
File metadata and controls
33 lines (28 loc) · 1.23 KB
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
package array1d;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new FileReader("./data/array1d/input"));
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
List<String> stringArray = bufferedReader.lines().collect(Collectors.toList());
stringArray.remove(0); //Not needed from HackerRank, using string.length (safer)
bufferedReader.close();
Solution solution = new Solution();
solution.printOutput(stringArray);
}
public void printOutput(List<String> stringArray) {
stringArray.stream().map(string
-> new ArrayList<>(List.of(string.split(" "))))
.forEach(strings -> {
Collections.reverse(strings);
String output = String.join(" ", strings);
System.out.println(output);
});
}
}