Java: Example - Count vowels
This example method counts all vowels (a, e, i, o, u) in a string.//-------------------------------------------- countVowels() int countVowels(String text) { int count = 0; // start the count at zero // change the string to lowercase text = text.toLowerCase(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { count++; } } return count; }