Creates a set of vowel letters. For Uniquewords.java operations, counts and displays the number of vowels in each input word and displays the sum of all the vowels in the input file.
Public classVOWELS6 {Static voidVowelcounter (set<string>St) {Set<Character> vowels =NewTreeset<character>(); Collections.addall (Vowels,' A ', ' e ', ' I ', ' o ', ' u ', ' a ', ' e ', ' I ', ' o ', ' u '); intAllvowels = 0; for(String s:st) {intCount = 0; for(Character V:s.tochararray ()) {if(Vowels.contains (v)) {count++; Allvowels++; }} System.out.print (S+ ":" + Count + ","); } System.out.println (); System.out.print ("Total vowels:" +allvowels); } Public Static voidMain (string[] args) {Set<String> words =NewTreeset<string>( NewTextfile ("Setoperations.java", "\\w+")); SYSTEM.OUT.PRINTLN (words); System.out.println (); Vowelcounter (words); } }
Java Programming Ideas Chapter 11th Exercise 16