Rocket
2012-04-07 06:35:07 UTC
The array returned by your method should hold 5 elements: the first is the count of As, the second is the count of Es, the third is the count of Is, the fourth is the count of Os, and the fifth is the count of Us.
You may assume that the string contains no uppercase letters.
For example, the call of vowelCount("black banana republic boots") should return an array containing {4, 1, 1, 2, 1}.
This is what I got so far:
import java.util.*;
public class Vowel {
public static void main(String[] args) {
vowelCount(text);
}
public static int[] vowelCount(String text) {
int[] counts = new int[5];
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == 'a') {
counts[0]++;
} else if (c == 'e') {
counts[1]++;
} else if (c == 'i') {
counts[2]++;
} else if (c == 'o') {
counts[3]++;
} else if (c == 'u') {
counts[4]++;
}
}
return counts;
}
}
Any help please and thanks!