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

结对的人:伪军;

 

 

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

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等等问题)。

 

posted on 2016-03-28 13:25  往事随风~~  阅读(307)  评论(3编辑  收藏  举报