一道Java题目,请大虾们帮帮忙,谢谢了

用Java编写一个程序,对于输入的一段英语文本,可以统计:
1、该文本中有多少英语单词;
2、该文本中有多少不同的英语单词。
如,输入 I am a good student. I am in Zhengzhou.
则可以统计出有9个英语单词、7个不同的英语单词。

首先,需要对输入信息进行处理,去掉输入的标点符号,并以空格替换,需要用正则表达式,进行全部替换;
其次,就是对输入单词进行统计,使用字符串的分割函数split(" "),以空格分割;
最后,就是遍历分割结果,进行统计,用Map,以单词为key,出现次数为value。
实例代码如下:

 import java.util.HashMap;
import java.util.Map;

public class Tee {
    /**
     * 正则去除所有的英文标点符号
     */
    public static String formatInput(String input) {
        if (input == null) {
            return null;
        }

        return input.replaceAll("[.|;|\\?]", " ");
    }

    public static Map<String, Integer> countWords(String input) {
        Map<String, Integer> result = new HashMap<String, Integer>();
        if (input == null || input.length() == 0) {
            return result;
        }
        // 用字符串的分割函数
        String[] split = input.split(" ");
        if (split == null || split.length == 0) {
            return result;
        }

        // 统计存入Map,word为key,出现次数为value
        for (String value : split) {
            if (result.containsKey(value)) {
                // 出现过,直接累计+1
                result.put(value, result.get(value) + 1);
            } else {
                // 没出现过存入
                result.put(value, 1);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String value = "I am a good student.I am in Zhengzhou.Ha?";
        String format = formatInput(value);
        System.out.println(format);
        Map<String, Integer> r = countWords(format);
        System.out.println(r.toString());
    }
}

http://www.zybang.com/question/a4b9597b12af739c8bf72d92e9c569fa.html
至于相同的单词,可以放在Map中汇总下。