Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vowel, your method should return false. Your method should return true if passed the empty string, since it does not contain any non-vowel characters.
For example, here are some calls to your method and their expected results:
Call | Value Returned |
isAllVowels("eIEiO") |
true |
isAllVowels("oink") |
false |
Code:
public static boolean isAllVowels(String s)
{
boolean flag = false;
for (int i = 0; i < s.length(); i++)
{
switch(Character.toLowerCase(s.charAt(i)))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
//case " " :
flag = true;
break;
default:
flag = false;
}
}
return flag;
}
public static void main (String args[])
{
System.out.println(isAllVowels("eIEiO"));
System.out.println(isAllVowels("oink"));
}