I'm doing this problem as practice for using methods outside of the main method. The problem needed us to make three different methods, each of which does a different task, but none of them have to relate with each other.
smallestNumber(): take 3 numbers inputted by the user and output the smallest number
average(): take 3 numbers inputted by the user and output the average
countVowels(): take a phrase inputted by the user and output the number of vowels in that phrase
For me, I am able to return a value from method 1 and method 2 back to the main method. For method 3, when I try to return the counter value, it ALWAYS returns 0 even if there ARE vowels in the phrase.
Can someone please explain what I am doing wrong? (sorry with indenting issues, I've never used Stack Overflow before)
I don't know why it keeps returning 0
public static int countVowels(String words) {
int count=0;
for (int i=0; i<words.length(); i++) {
if (words.charAt(i) == 'a' || words.charAt(i) == 'e' || words.charAt(i) == 'i' || words.charAt(i) == 'o' || words.charAt(i) == 'u') {
count++;
}
}
return(count);
}