编写一个程序,对于输入的一段英语文本,可以统计:
1、该文本中有多少英语单词;
2、该文本中有多少不同的英语单词。
如:输入 I am a good student. I am in Zhengzhou.
则可以统计出有9个英语单词,7个不同的英语单词。
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;
}
for (String value : split) {
if (result.containsKey