Checking if all five vowels are present in a string.
String phrase = "Hello, how are you keeping?";
String vowelsInPhrase = phrase.toLowerCase().replaceAll("[^aeiou]", "");
String temp = vowelsInPhrase;
String usedVowels = "";
while(temp.length() > 0){
usedVowels += temp.substring(0, 1);
temp = temp.replaceAll(temp.substring(0, 1), "");
}
if(usedVowels.length() == 5){
result += "At least one occurrence of each vowel.\n";
}
Does anyone have a better solution?? I am thinking some sort of pattern to check if each required character has appeared one or more times but I don't know if it is possible. This would save using the while loop.
Something like this is what I was thinking:
String pattern = "[[a]+[e]+[i]+[o]+[u]+]";
if(usedVowels.matches(pattern){
result += "At least one occurrence of each vowel.\n";
}