元音字母计数
import java.util.*; public class CountVowels {/*nowjava 提 供*/ public static void main(String[] args) { if (args.length < 1) { System.err.println("Usage: java CountVowels <word1 word2 ...>"); System.exit(1); } Map<String, Integer> msi = new HashMap<>(); for (String s : args) { int vowelCount = 0; int length = s.length(); /* 来 自* 时 代 J a v a */ for (int i = 0; i < length; ++i) if (isVowel(s.charAt(i))) ++vowelCount; msi.put(s, vowelCount); } Set<String> words = msi.keySet(); for (String wd : words) System.out.println(wd + ": " + msi.get(wd)); } public static boolean isVowel(char c) { return c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U'; } }