Write a method named isAllVowels that returns whether a String consists entirely
ID: 3531024 • Letter: W
Question
Write a method namedisAllVowelsthat returns whether aStringconsists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of theStringis a vowel, your method should returntrue. If any character of theStringis a non-vowel, your method should returnfalse. Your method should returntrueif 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
Explanation / Answer
please rate
public class SyncABC{
public static void main(String[] args) {
SyncABC obj=new SyncABC();
Scanner input= new Scanner(System.in);
String str=input.nextLine();
System.out.println(obj.isAllVowels(str));
}
public boolean isAllVowels(String str)
{
char ch;
for(int i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
else
return false;
}
return true;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.