public int countVowels(String str) { int count = 0; if (str.length() > 0) { String vowels = "aeiou"; // Loop through each letter of string, lowercase it and look for it // in our string of vowels. for (int i = 0; i < str.length(); i++) { if (vowels.indexOf(str.toLowerCase().charAt(i)) != -1) { count++; } } } return count; }
Posted: March 20, 2023
Return to the snippets listing