当前位置 : 主页 > 编程语言 > c++ >

java统计英语单词词频

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt import java.lang.reflect.Array;import java.util.HashMap;import java.util.Scanner;public class Worda {public static void main(String[] args) {HashMap map = new HashMap();Scanner scan = new Scanner(System.in);String inputStr = s
gistfile1.txt
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Scanner;

public class Worda {

	public static void main(String[] args) {
		HashMap map = new HashMap();
		Scanner scan = new Scanner(System.in);
		String inputStr = scan.nextLine();
		scan.close();
		String[] words = inputStr.split("[^a-zA-Z]");
		for(String word : words){
			System.out.println(word);
		}
		for(int i = 0; i < Array.getLength(words); i++){
			String temp = words[i];
			if(map.containsKey(temp) == true){
				Integer v = (Integer)map.get(temp);
				map.put(temp, v.intValue()+1);
			}else{
				map.put(temp, 1);
			}
		}
		System.out.println(map);
	}
}
网友评论