Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
|
|
@ -0,0 +1,22 @@
|
|||
public class ReverseWords {
|
||||
|
||||
static final String[] lines = {
|
||||
" ----------- Ice and Fire ----------- ",
|
||||
" ",
|
||||
" fire, in end will world the say Some ",
|
||||
" ice. in say Some ",
|
||||
" desire of tasted I've what From ",
|
||||
" fire. favor who those with hold I ",
|
||||
" ",
|
||||
" ... elided paragraph last ... ",
|
||||
" Frost Robert ----------------------- "};
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (String line : lines) {
|
||||
String[] words = line.split("\\s");
|
||||
for (int i = words.length - 1; i >= 0; i--)
|
||||
System.out.printf("%s ", words[i]);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package string;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
|
||||
public interface ReverseWords {
|
||||
public static final String[] LINES = {
|
||||
" ----------- Ice and Fire ----------- ",
|
||||
" ",
|
||||
" fire, in end will world the say Some ",
|
||||
" ice. in say Some ",
|
||||
" desire of tasted I've what From ",
|
||||
" fire. favor who those with hold I ",
|
||||
" ",
|
||||
" ... elided paragraph last ... ",
|
||||
" Frost Robert ----------------------- "
|
||||
};
|
||||
|
||||
public static String[] reverseWords(String[] lines) {
|
||||
return stream(lines)
|
||||
.parallel()
|
||||
.map(l -> l.split("\\s"))
|
||||
.map(ws -> stream(ws)
|
||||
.parallel()
|
||||
.map(w -> " " + w)
|
||||
.reduce(
|
||||
"",
|
||||
(w1, w2) -> w2 + w1
|
||||
)
|
||||
)
|
||||
.toArray(String[]::new)
|
||||
;
|
||||
}
|
||||
|
||||
public static void main(String... arguments) {
|
||||
stream(reverseWords(LINES))
|
||||
.forEach(System.out::println)
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue