java - Returning vowels -
i beginner in java, , doing practice on practiceit.
but got stumbled on question.
write method named isvowel
returns whether string
vowel (a single-letter string containing a, e, i, o, or u, case-insensitively).
public static boolean isvowel(string word){ for(int i=0;i<word.length();i++){ char vowels=word.charat(i); if(vowels== 'a'|| vowels =='e' || vowels=='i'|| vowels == 'o' || vowels == 'u'|| vowels== 'a'|| vowels =='e' || vowels=='i'|| vowels == 'o' || vowels == 'u' ){ return true; } } return false; }
this code works when test "hello". no longer works. understand because condition char loops 1 one , not word whole.but cant figure out.will appreciate if give me hints instead of answer.
your question quite confusing. string might have vowel, proper english "word" single letter "i".
this method should named "hasvowel" or "containsvowel". in case, looping on each letter , returning true if has vowel makes sense.
Comments
Post a Comment