Didart

Count Uppercase Words

Jan 30th, 2023
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package FunctionalProgramming;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6. import java.util.function.Predicate;
  7.  
  8. public class CountUppercaseWords {
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         Scanner scan = new Scanner(System.in);
  12.         String[] textAsList = scan.nextLine().split("\\s+");
  13.         Predicate<String> checkerUpperCase =
  14.                 word -> Character.isUpperCase(word.charAt(0));
  15.         ArrayList<String> result = new ArrayList<>();
  16.         for (int i = 0; i < textAsList.length; i++) {
  17.             if (checkerUpperCase.test(textAsList[i]))
  18.                 result.add(textAsList[i]);
  19.         }
  20.         System.out.println(result.size());
  21.         result.forEach(System.out::println);
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment