print(count_vowels("camera"));
}
int count_char(char word, String sentence) {
int totalChar = 0;
for (int i = 0; i< sentence.length (); i++) {
if (word == sentence.charAt(i)) {
totalChar = totalChar + 1;
}
}
return totalChar;
}
int count_vowels(String sentence) {
int tatalVowels = 0;
String vowels = "aeiou";
for (int i = 0; i < vowels.length (); i++) {
tatalVowels = tatalVowels + count_char(vowels.charAt(i), sentence);
}
return tatalVowels;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น