Could please someone help me to fulfill the "The second line should contain only the consonants and punctuation marks from the input string, separated by a space." condition?
Thx!
package com.codegym.task.task09.task0923;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Vowels and consonants
*/
public class Solution {
public static char[] vowels = new char[]{'a', 'e', 'i', 'o', 'u'};
public static void main(String[] args) throws Exception {
// write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
char[] input = reader.readLine().toCharArray();
ArrayList<String> vowels = new ArrayList<>();
ArrayList<String> others = new ArrayList<>();
for (int i = 0; i < input.length; i++) {
if(isVowel(input[i])) {
vowels.add(String.valueOf(input[i] + " "));
}
else {
others.add(String.valueOf(input[i] + " "));
}
}
for (int i = 0; i < vowels.size(); i++) {
System.out.print(vowels.get(i));
}
System.out.println();
for (int i = 0; i < others.size(); i++) {
System.out.print(others.get(i));
// others.replaceAll();
}
}
// The method checks whether a letter is a vowel
public static boolean isVowel(char c) {
c = Character.toLowerCase(c); // Convert to lowercase
for (char d : vowels) // Look for vowels in the array
{
if (c == d)
return true;
}
return false;
}
}