deyanmalinov

3. Count Uppercase Words - 2

Apr 11th, 2020
201
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6. import java.util.function.Predicate;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.         String[] textAsList = scan.nextLine().split("\\s+");
  12.         Predicate<String> checkerUpperCase =
  13.                 word -> Character.isUpperCase(word.charAt(0));
  14.         ArrayList<String> result = new ArrayList<>();
  15.         for (int i = 0; i < textAsList.length; i++) {
  16.             if (checkerUpperCase.test(textAsList[i]))
  17.                 result.add(textAsList[i]);
  18.         }
  19.         System.out.println(result.size());
  20.         result.forEach(System.out::println);
  21.     }
  22. }
RAW Paste Data