一、今日学习内容

统计例题:

   1、题目一:文章统计(统计一篇英文文章中单词的个数与行数)

源程序代码:

复制代码
 1 import java.io.FileReader;
 2 import java.io.IOException;
 3 import java.io.BufferedReader;
 4 public class English {
 5 
 6     public static void main(String[] args)throws IOException {
 7         readfiles();
 8     }
 9     public static void readfiles()throws IOException{
10         FileReader r=new FileReader("F://English.txt");
11         BufferedReader br=new BufferedReader(r);
12         int countWord=0;
13         int countLine=0;
14         String s=null;
15         while((s=br.readLine())!=null) {
16             System.out.println(s);
17             countWord += s.split("\\s+|,|\\.").length;
18             countLine++;
19         }
20         System.out.println("单词数为:"+countWord);
21         System.out.println("行数为:"+countLine);
22         r.close();
23         br.close();
24     }
25 }
复制代码

二、遇到的问题

  不清楚split()分割字符串的用法,百度搜索。

三、明日计划

  继续完成例题的验证。

posted on 2020-08-27 17:49  白日梦想家~  阅读(45)  评论(0编辑  收藏  举报