if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { count++;
When i give the above statement it returns number of vowels in a word only if the given word is in lowercase (ie: input: friend output 2 vowels). I Want to know even if i give uppercase or mixed it should return number of vowels. How to do it?
One succint, simple way to do this without doing 10 comparisons:
if ("aeiouAEIOU".indexOf(c) != -1) { count++; }
Here there is a complete example - note they turn the string to lower case before checking the vowels.
You can also try with a case insensitive regular expression, example from http://www.shiffman.net/teaching/a2z/regex/:
String regex = "[aeiou]";
Pattern p = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
int vowelcount = 0;
Matcher m = p.matcher(content); // Create Matcher
while (m.find()) {
//System.out.print(m.group());
vowelcount++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With