统计英文article.txt文件中出现hello这个单词的次数

这个是article.txt文件内容 {

hello The Royal Navy is trying hello to play hello down the problem,
after first trying to hide it. It is clearly embarrassing.
They have hello known about the problem for hello some time
but they did not hello want it hello to get in the way of the
commissioning hello ceremony hello in front hello of the Queen. hello

}

package ltb20180106;

import java.io.*;

public class WordCount  {

private File f;
private BufferedReader br;
private BufferedWriter bw;
private String readline;
private int start=0;
private int end=0;
private int count=0; public WordCount() { try { f=new File("D:\\myRead\\article.txt");
br=new BufferedReader(new FileReader(f));
bw=new BufferedWriter(new OutputStreamWriter(System.out)); while((readline=br.readLine())!=null) { start=this.readline.indexOf("hello"); if(start!=-1) { // 一行字符串中如果有hello出现就进行统计 count++; end=this.readline.indexOf("hello",start+1); while(end!=-1) { //如果在这行中后续还有hello出现,继续统计,直到末尾没有hello出现为止。 count++; System.out.print("[end:"+end+"]"+","); end=this.readline.indexOf("hello",end+1); }
} bw.write(readline+"\r"); System.out.println("累计总共的次数:【"+count+"】"+"start:【"+start+"】"); bw.flush();
} System.out.println("单词hello在文章【"+f.getName()+"】中出现的次数为:【"+count+"】"); bw.close(); }catch(Exception e) { e.getMessage();
} } public static void main(String[] args) { new WordCount();
} }

Java 中统计文件中出现单词的次数练习的更多相关文章

  1. Java版统计文件中的每个单词出现次数

    正则表达式之Pattern和Matcher,请参见转载博客    http://www.cnblogs.com/haodawang/p/5967219.html 代码实现: import java.i ...

  2. linux中统计文件中一个字符串出现的次数

    要统计一个字符串出现的次数,这里现提供自己常用两种方法: 1. 使用vim统计 用vim打开目标文件,在命令模式下,输入 :%s/objStr//gn 2. 使用grep: grep -o objSt ...

  3. sort +awk+uniq 统计文件中出现次数最多的前10个单词

    实例cat logt.log|sort -s -t '-' -k1n |awk '{print $1;}'|uniq -c|sort -k1nr|head -100 统计文件中出现次数最多的前10个单 ...

  4. Java笔记13:统计文件中每个字符出现的次数

    一.代码实现 import java.io.*; import java.util.*; /** 功能:统计文件中每个字符出现的次数 思路: 1.定义字符读取(缓冲)流 2.循环读取文件里的字符,用一 ...

  5. Scala快速统计文件中特定单词,字符的个数

    val fileContent=Source.fromFile("/home/soyo/桌面/ss5.txt").getLines.mkString(",") ...

  6. 学c语言做练习之​统计文件中字符的个数

    统计文件中字符的个数(采用命令行参数) #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[] ...

  7. linux命令统计文件中某个字符串出现的次数

    1.使用grep linux grep命令在我的随笔linux分类里有过简单的介绍,这里就只简单的介绍下使用grep命令统计某个文件这某个字符串出现的次数,首先介绍grep命令的几个参数,详细参数请自 ...

  8. excel中统计列中的值在其他列出现的次数多个条件

    excel中统计列中的值在其他列出现的次数多个条件 =COUNTIFS(E2:E373,"=VIP经销商",J2:J373,K2) 解释 E列的第二行到第373行中值 等于 VIP ...

  9. rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少?

    rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少? 结论 对于 8 来说,通过以下命令 #/usr/libexec/platform-python -c 'impor ...

随机推荐

  1. threejs 空间位置转为屏幕像素xy位置

    function createVector(x, y, z, camera, width, height) { var p = new THREE.Vector3(x, y, z); var vect ...

  2. Linux make menuconfig查找并快速跳转指定驱动选项

    /********************************************************************** * Linux make menuconfig查找并快速 ...

  3. 【leetcode】21-MergeTwoSortedLists

    problem MergeTwoSortedLists 一种方法是迭代,一种方法是递归: code /** * Definition for singly-linked list. * struct ...

  4. LAMP搭建个人网站

    最近发了一篇paper,需要把成果展示出来,想到正好想到自己有一个阿里云服务器,并且在万网上看到www.yongjieshi.com这个域名一年才50块钱,于是决定搭建一个自己的网站 如果linux玩 ...

  5. 九度OJ1108-堆栈的使用

    题目1108:堆栈的使用 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11620 解决:3372 题目描述: 堆栈是一种基本的数据结构.堆栈具有两种基本操作方式,push 和 pop.P ...

  6. Sonar理论篇

    一.Sonar是什么    Sonar是一个代码质量管理的开源平台,用于管理源代码的质量,通过插件形式,可以支持包括java.C#.JavaScript等二十余种编程语言的代码质量管理与检测. Son ...

  7. MySql查询出来的值为 boolean类型的值

    解决方案: status_flag * 1 as status_flag 乘以1之后就不会是boolean类型的值了

  8. python开发day02

    一 while循环 while 条件 代码块(循环体)  #:  判断条件是否为真,如果是真,则执行代码块, 然后再次回头判断条件是否为真,如果为真,则只执行代码块.......知道循环的判断出代码为 ...

  9. YIT-CTF—隐写术

    一:小心心 下载图片——>改后缀名为TXT——>打开发下最后一行有flag 二:双生 下载两张图片——>应为题目说的是双生——>想到可能是两张图片的叠加——>打开图片查看 ...

  10. hdu4553 约会安排 线段树

    寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑,由于数量实 ...