代码语言:javascript复制
// 词频统计
class CountWords {
public static int count() {
int count = 0;
System.out.println("请输入英文句子");
Scanner r = new Scanner(System.in);
String str = r.nextLine();
// 分割子串
String arr[] = str.split("[',','.','?',' ','!',';',' ']");
// for (String c : arr) {
// System.out.print(c);
// }
System.out.println("请输入统计的单词");
String wd = r.nextLine();
for (int i = 0; i < arr.length; i ) {
System.out.print('n' arr[i]);
if (wd.equals(arr[i])) {
count ;
}
}
return count;
}
}