作业4.2
2016-03-29 20:34
453 查看
本次实验和 范鋆 同学结对完成。
本次程序在上次程序上稍加改动,增加搜索单词的功能,主要代码如下:
实验数据:
我搜索了3个单词 that with have,并和上次结果对比
结果一致
github地址:https://github.com/sunhongyi1996/repository
本次程序在上次程序上稍加改动,增加搜索单词的功能,主要代码如下:
public static void main(String[] args) { Scanner in=new Scanner(System.in); System.out.println("请输入想要查找的单词"); String m=in.nextLine(); int count=0; try{ FileReader fr1=new FileReader("Gone_with_the_wind.txt"); //读取 BufferedReader bf1=new BufferedReader(fr1); String str=null; while( (str=bf1.readLine())!=null) { str=str.replace("\\n", ""); str=str.toLowerCase(); str=str.replaceAll("[\\pP‘’“”]", ""); String[] str1=str.split(" "); for(int i=0;i<str1.length;i++) { if(m.equals(str1[i]))count++; } } fr1.close(); bf1.close(); }catch(Exception e){e.printStackTrace();} try{ FileWriter fw=new FileWriter("Result1.txt"); BufferedWriter bw=new BufferedWriter(fw); bw.write(m+"="+count); bw.close();fw.close(); }catch(Exception e){e.printStackTrace();} } }
实验数据:
我搜索了3个单词 that with have,并和上次结果对比
结果一致
github地址:https://github.com/sunhongyi1996/repository
相关文章推荐
- PHP 基本用法及基本知识点
- duplicate symbol _OBJC_IVAR_$
- 求n的阶乘
- 【剑指 offer】—— 快速排序
- struts2实现让文件输入流流向浏览器显示
- 第5周项目1—三角形类雏形(2、内联成员函数)
- js学习
- 设置一个三角形类(3)
- nyoj 1045 看美女(二)
- 好的资源
- VirtualBox5教程二:如何调整ubuntu显示分辨率、大小
- Android之aapt
- 新旧图幅号转换公式及示例代码(C#)
- 基于qt的嵌入式Linux开发环境搭建
- docker私有仓库搭建(ubuntu 14.04和centos7)
- linux动态库编译和使用详细剖析
- XML解析中SAX和Pull的区别
- 重载函数的运用。。。分别求两个整数平方和 及 两个实数的平方和
- 前端技术
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)