Advertisement
veronikaaa86

04. Word Filter

Jul 6th, 2022
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package associativeArrays;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class P04WordFilter {
  9. public static void main(String[] args) {
  10. Scanner scanner = new Scanner(System.in);
  11.  
  12. String[] wordsArr = Arrays.stream(scanner.nextLine().split(" "))
  13. .filter(e -> e.length() % 2 == 0)
  14. .toArray(String[]::new);
  15.  
  16. System.out.println(String.join(System.lineSeparator(), wordsArr));
  17.  
  18.  
  19. // String[] wordsArr = scanner.nextLine().split(" ");
  20. //
  21. // List<String> resultList = new ArrayList<>();
  22. // for (int i = 0; i < wordsArr.length; i++) {
  23. // int len = wordsArr[i].length();
  24. //
  25. // if (len % 2 == 0) {
  26. // resultList.add(wordsArr[i]);
  27. // }
  28. // }
  29. //
  30. // for (String s : resultList) {
  31. // System.out.println(s);
  32. // }
  33.  
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement