import java.io.*;
import java.lang.*;

public class WordStatistic  {


   private BufferedReader br;
   private String s;
   private StringBuffer sb;
   private char[] c;
    

    WordStatistic(String parent,String child ) {

        sb=new StringBuffer();

        try {

            br=new BufferedReader(new FileReader(new File(parent,child)));

        }catch (IOException e) {

            e.getMessage();
        }


    }

    public void getWordStatistic()throws IOException  {

         int n =0; // a-z 之间
         int m=0;  //A-Z 之间
         int k=0;
        while ((s=br.readLine())!=null){

          sb.append(s);

        }

        s=sb.toString();
        c=s.toCharArray();
        System.out.println("开始统计了:");
        for(char i:c) {

                if(i>='a'&&i<='z') { //字符是''
                    n=n+1;
                }else if(i>='A'&&i<='Z') {
                    m=m+1;
                }else {
                    k=k+1;
                }
        }

        System.out.println("a-z之间的字母是:"+n+"个");
        System.out.println("A-Z之间的字母是:"+m+"个");
        System.out.println("不是字母的其他是:"+k+"个");



    }

    public static  void  main(String[] args) throws IOException {

         WordStatistic ws=new WordStatistic("D:\\myRead","WriteLog.txt");
         ws.getWordStatistic();
    }

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-06-04
  • 2021-06-18
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案