面试题01给你一个英语句子,每个单词由一个或多个空格分开,含有原因字母的单词个数 a e i o u

459 阅读1分钟
/**
 * 给你一个英语句子,每个单词由一个或多个空格分开,含有原因字母的单词个数 a e i o u
 *
 * @return
 */
 
public static int numberOfVowelWords() {
    int count = 0;
    Scanner san = new Scanner(System.in);
    if (san.hasNext()) {
        char[] result = san.nextLine().toCharArray();
        HashSet<String> set = new HashSet<String>();
        set.add("a");
        set.add("e");
        set.add("i");
        set.add("o");
        set.add("u");
        HashMap hashMap = new HashMap();
        int i, j = 0;
        for (i = 0; i < result.length; i++) {
            if (Integer.valueOf(result[i]) != 32) {
                boolean tag = true;
                for (j = i; j < result.length; j++) {//内循环,寻找单词的个数
                    if (Integer.valueOf(result[j]) != 32) {
                        if (set.contains(String.valueOf(result[j]))) {
                            if (tag) {
                                count++;
                                tag = false;
                            }
                        }
                    } else if (Integer.valueOf(result[j]) == 32) {
                        i = j;
                        break;
                    }
                }
            }
        }
    }
    System.out.println(count);
   return count;
}