Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;  // 75/100
  4.  
  5. public class _04_Split_by_Word_Casing {
  6.      public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.         String[] text = input.split("[ \\[\\],;\\\\:.!/()\"']+");
  11.  
  12.         ArrayList<String> sentence = new ArrayList<>();
  13.         for (String word : text)
  14.         {
  15.             sentence.add(word);
  16.         }
  17.  
  18.         ArrayList<String> lowerCaseWords = new ArrayList<>();
  19.         ArrayList<String> mixedCaseWords = new ArrayList<>();
  20.         ArrayList<String> upperCaseWords = new ArrayList<>();
  21.  
  22.         for (String word : sentence)
  23.         {
  24.             boolean isMixed = false;
  25.             for (int i = 0; i < word.length(); i++)
  26.             {
  27.                 if (!Character.isLetter(word.charAt(i)))
  28.                 {
  29.                     isMixed = true;
  30.                     break;
  31.                 }
  32.             }
  33.             if (word.toUpperCase().equals(word) && !isMixed && !word.isEmpty()){
  34.  upperCaseWords.add(word);
  35. } else if (word.toLowerCase().equals(word) && !isMixed && !word.isEmpty()) {
  36.     lowerCaseWords.add(word);
  37. } else if (!word.isEmpty()){
  38.     mixedCaseWords.add(word);
  39. }
  40.         }
  41.         System.out.println("Lower-case: " + String.join(", ", lowerCaseWords));
  42.         System.out.println("Mixed-case: " + String.join(", ", mixedCaseWords));
  43.         System.out.println("Upper-case: " + String.join(", ", upperCaseWords));
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement