deyanmalinov

3. Count Uppercase Words

Jun 5th, 2019
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  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[] sentense = scan.nextLine().split("\\s+");
  12.         Predicate<String> toUpper = word ->  {
  13.             return  word.charAt(0) == word.toUpperCase().charAt(0);
  14.         };
  15.         List<String> words = new ArrayList<>();
  16.  
  17.         for (String str : sentense) {
  18.             if (toUpper.test(str)){
  19.                 words.add(str);
  20.             }
  21.         }
  22.  
  23.         System.out.println(words.size());
  24.         words.forEach(System.out::println);
  25.     }
  26. }
RAW Paste Data