?? vowels20.java
字號:
// holding/Vowels20.java
// TIJ4 Chapter Holding, Exercise 20, page 422
// Modify Exercise 16 so that you keep a count of the occurence of each vowel.
import java.util.*;
import net.mindview.util.*;
public class Vowels20 {
static void vowelCounter20(Set<String> st) {
Set<Character> vowels = new TreeSet<Character>();
Collections.addAll(vowels,
'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u');
int allVowels = 0;
Map<Character,Integer> vowelMap =
new TreeMap<Character,Integer>();
for(String s : st) {
for(Character v : s.toCharArray()) {
if(vowels.contains(v)) {
Integer count = vowelMap.get(v);
vowelMap.put(v,
count == null ? 1 : count + 1);
allVowels++;
}
}
}
System.out.println("Vowels: " + vowelMap);
System.out.println("Total vowels: " + allVowels);
}
public static void main(String[] args) {
Set<String> words = new TreeSet<String>(
new TextFile("SetOperations.java", "\\W+"));
System.out.println(words);
System.out.println();
vowelCounter20(words);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -