Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner; // 75/100
- public class _04_Split_by_Word_Casing {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] text = input.split("[ \\[\\],;\\\\:.!/()\"']+");
- ArrayList<String> sentence = new ArrayList<>();
- for (String word : text)
- {
- sentence.add(word);
- }
- ArrayList<String> lowerCaseWords = new ArrayList<>();
- ArrayList<String> mixedCaseWords = new ArrayList<>();
- ArrayList<String> upperCaseWords = new ArrayList<>();
- for (String word : sentence)
- {
- boolean isMixed = false;
- for (int i = 0; i < word.length(); i++)
- {
- if (!Character.isLetter(word.charAt(i)))
- {
- isMixed = true;
- break;
- }
- }
- if (word.toUpperCase().equals(word) && !isMixed && !word.isEmpty()){
- upperCaseWords.add(word);
- } else if (word.toLowerCase().equals(word) && !isMixed && !word.isEmpty()) {
- lowerCaseWords.add(word);
- } else if (!word.isEmpty()){
- mixedCaseWords.add(word);
- }
- }
- System.out.println("Lower-case: " + String.join(", ", lowerCaseWords));
- System.out.println("Mixed-case: " + String.join(", ", mixedCaseWords));
- System.out.println("Upper-case: " + String.join(", ", upperCaseWords));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement