Hi Guys,
Can you help out? My current output is:
[a, I, A]
[S, m, m, .]
How can I trim the commas and brackets?
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));
String s = reader.readLine();
ArrayList<Character> vowels = new ArrayList<>();
ArrayList<Character> consonantsAndPunctuationMarks = new ArrayList<>();
char[] charString = s.toCharArray();
char space = ' ';
for (int i = 0; i < charString.length;i++){
char vowel = charString[i];
if (vowel == space) continue;
else if (isVowel(vowel)){vowels.add(vowel);}
else {consonantsAndPunctuationMarks.add(vowel);}
}
System.out.println(vowels);
System.out.println(consonantsAndPunctuationMarks);
}
// 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;
}
}