Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method named isAllVowels that returns whether a String consists entirely

ID: 3557496 • Letter: W

Question

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:

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"));
}

Call Value Returned isAllVowels("eIEiO") true isAllVowels("oink") false

Explanation / Answer

public class VowelOrNot

{

public static void main (String args[])
{

System.out.println(isAllVowels("eIEiO"));
System.out.println(isAllVowels("oink"));
}

public static boolean isAllVowels(String s)
{
boolean flag = false;

if(s == "" )

{

return true;

}
for (int i = 0; i < s.length(); i++)
{

char ch = Character.toLowerCase(s.charAt(i));

if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' )

{

flag = true;

}

else

{

flag = false;

break;

}

}

return flag;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote