daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Nov 25th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private static final String SPACE_DELIMITER = " ";
  2.     private static final String VOWELS_CHARS = "AaEeUuIiOoYy";
  3.  
  4.     private void sixthTask() {
  5.         System.out.println("Sixth task");
  6.  
  7.         String[] sentences = requestStringsInput();
  8.  
  9.         System.out.println("Enter edge length of words to remove:");
  10.  
  11.         int edgeLength = Integer.valueOf(scanner.nextLine());
  12.  
  13.         for (String sentence : sentences) {
  14.             String resultSentence = removeWordsSmallerThan(sentence, edgeLength);
  15.             System.out.println(resultSentence);
  16.         }
  17.     }
  18.  
  19.     private String removeWordsSmallerThan(String sentence, int edgeLength) {
  20.         StringBuilder sb = new StringBuilder();
  21.         String[] words = sentence.split(SPACE_DELIMITER);
  22.  
  23.         for (String word : words) {
  24.             if (word.length() == edgeLength && !isVowelChar(word.charAt(0)))
  25.                 continue;
  26.  
  27.             sb.append(word).append(SPACE_DELIMITER);
  28.         }
  29.  
  30.         return sb.toString().trim();
  31.     }
  32.  
  33.     private boolean isVowelChar(char ch) {
  34.         return VOWELS_CHARS.contains(String.valueOf(ch));
  35.     }
  36.  
  37.     private String[] requestStringsInput() {
  38.         System.out.println("Enter count of strings to enter: ");
  39.  
  40.         int count = Integer.valueOf(scanner.nextLine());
  41.  
  42.         System.out.println("Enter " + count + " strings:");
  43.  
  44.         String[] strings = new String[count];
  45.  
  46.         for (int i = 0; i < count; i++) {
  47.             strings[i] = scanner.nextLine();
  48.         }
  49.  
  50.         return strings;
  51.     }
RAW Paste Data
Top