文章获取与单词统计排序
来源:互联网 发布:李谷一 知乎 编辑:程序博客网 时间:2024/06/05 16:52
/****************** Exercise 21 ****************** Using a Map<String,Integer>, follow the form of* UniqueWords.java to create a program that counts* the occurrence of words in a file. Sort the* results using Collections.sort() with a second* argument of String.CASE_INSENSITIVE_ORDER (to* produce an alphabetic sort), and display the result.***********************************************/import java.util.*;import net.mindview.util.*;public class E21_WordsNumber {public static void main(String[] args){//countFileWord("E21_WordsNumber.java");}public static void countFileWord(String fileName){//m1插入String.CASE_INSENSITIVE_ORDER,非题中要求Map<String, Integer> m1 = new TreeMap<String, Integer> (String.CASE_INSENSITIVE_ORDER);List<String> words1 = new TextFile(fileName, "\\W+");for(String word: words1)countWord(m1, word);System.out.println("the number of every word is: " + m1);//按题要求如下:Map<String, Integer> m2 = new TreeMap<String, Integer> ();List<String> words2 = new TextFile(fileName, "\\W+");for(String word: words2)countWord(m2, word);List<String> keys = new ArrayList<String>(m2.keySet());Collections.sort(keys, String.CASE_INSENSITIVE_ORDER);for(String key: keys){System.out.print(key + ">=" + m2.get(key) + ". ");}System.out.println();}private static void countWord(Map<String, Integer> m, String s){Integer freq = m.get(s);m.put(s, freq == null? 1: freq+1);}}
阅读全文
0 0
- 文章获取与单词统计排序
- 统计文章相同单词
- 使用 HashMap统计文章单词
- python统计文章单词次数
- python 统计文章单词个数
- java实现读取一篇英文文章,统计其中每个单词出现的次数并排序输出
- 统计文章中单词的字数并按照出现的频率排序(treeSet)
- 统计单词个数排序输出
- 统计文章中单词出现的次数
- 统计英文文章单词JAVA代码
- 统计文章的单词各数
- 统计文章中相同单词的个数
- 统计目录下所有文章单词数量
- 统计英文文章中单词出现次数
- 统计文章中单词的个数
- Python 统计文章单词出现频率
- 统计文章中单词出现的次数
- 输入文章,统计各个单词出现次数
- Qt加载磁盘文件和对文件内容进行过滤
- MD5简单加密
- 单源最短路径算法(Dijkstra算法)
- 蒟蒻复习之-----Tarjan
- 在Linux下安装MySQL
- 文章获取与单词统计排序
- [bzoj4552][Tjoi2016&Heoi2016]排序 二分+线段树
- 河城荷取 二分答案 最大流
- 51Nod 1035 最长的循环节
- [java]创建新数组的三种方式
- 字符串的连接
- HBase之——Shell基础操作
- LeetCode 328. Odd Even Linked List
- 设置坐标轴长度和范围