import java.util.ArrayList; import java.util.Arrays; public class Ex01AverageVowels { public static boolean isVowel(char ch) { switch (Character.toLowerCase(ch)) { case 'a': case 'e': case 'i': case 'o': case 'u': return true; default: return false; } } public static void main(String[] args) { String[] strs = { "Hello", "in", "there", "how", "are", "you", "feeling", "this", "morning" }; List list = new ArrayList( Arrays.asList(strs) ); int nVowels = 0; int totalLetters = 0; for (String word : list) { totalLetters += word.length(); for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); if (isVowel(ch)) { nVowels++; } } } System.out.printf("#Vwl=%d #totalLetters=%d Ratio=%1.2f\n", nVowels, totalLetters, (double)nVowels/totalLetters); } }