fork download
  1. import java.util.*;
  2. import java.util.stream.*;
  3. class Ideone
  4. {
  5. public static void main(String[] args) {
  6. String sentence = "Who lives in a pineapple under the sea?";
  7. System.out.println(spinWords(sentence));
  8. }
  9.  
  10. public static String spinWords(String sentence) {
  11. return Arrays.stream(sentence.split(" "))
  12. .map(word -> word.length() < 5 ? word : new StringBuilder(word).reverse().toString())
  13. .collect(Collectors.joining(" "));
  14. }
  15. }
Success #stdin #stdout 0.11s 49344KB
stdin
Standard input is empty
stdout
Who sevil in a elppaenip rednu the sea?