飘英文单词统计

package javaClassHomework;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.TreeMap;
public class statistics
{
    public static void main(String [] args) throws IOException {
         BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\kkk.txt"));        
        int c;
        TreeMap<String,Integer> hm=new TreeMap<>();
        String line;
        int kt=0;
        while((line=br.readLine())!=null) {
            String [] str=line.split("[^a-zA-Z]");            
            for(int i=0;i<str.length;i++) {
                if(!str[i].equals("")) {
            hm.put(str[i],hm.containsKey(str[i])?hm.get(str[i])+1:1);}
            }
            }    
        br.close();
        int max=0;
        for(String k: hm.keySet()) {
              if(hm.get(k)>=max) {
                  max=hm.get(k);
              }
          }
        for(String k: hm.keySet()) {
            if(hm.get(k)==max) {
                System.out.println(k+":"+hm.get(k));                    
        }    
        }              
}}

 

posted @ 2019-09-26 22:54  派大星球日记  阅读(275)  评论(0编辑  收藏  举报