首页 > 其他 > 详细

作业4(必做2)----指定词频统计

时间:2016-03-28 15:11:39      阅读:257      评论:0      收藏:0      [点我收藏+]

结对的人:伪军;

 

 

必做二就是在必做一的基础上添加了一个查找,个人觉得不是很难;

public static void main(String arg[]) {   
	System.out.println("请输入文件名");
	Scanner in = new Scanner(System.in);
    String str = in.next();
    System.out.println("查找的单词为:");
    String s1 = in.next();
    Scanner in1 = new Scanner(System.in);
    File file=new File("F:\\"+str+".txt");
    String sentence= txt2String(file); 

 这里添加了一个输入用于查找的单词;

 String s3 = id.getKey();
    	 if(s3.equals(s2 )) { 	   
             error++;
    		 System.out.println(id.getKey()+"出现的次数为:"+id.getValue());
           
           }

       }
   }  
  if(error==0) System.out.println("没有这个单词!");

 

 这条语句用来比较输出查找的单词的次数(s1的值赋予了s2);

下面是测试的结果:

1.当查找小文件时;

请输入文件名
abc
查找的单词为:
times
times出现的次数为:2

 2,。当查找大文件时

123
查找的单词为:
that
that出现的次数为:4656

 对比必做一的结果:

that:4656
with:3368
scarlett:2438
they:2343
were:2076
would:1704
have:1654
from:1634
could:1537
said:1507
them:1428
there:1423
when:1414

 测试正确

 

 

完整代码github链接:https://github.com/Yizhongmeng/Mengzhongyi/

结对工作细节:两人都进行了对必做一的修改;不过经过讨论趋于完善(例如字符串比较,调用string等等问题)。

 

作业4(必做2)----指定词频统计

原文:http://www.cnblogs.com/zhongyimeng/p/5328694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!