zoukankan      html  css  js  c++  java
  • JAVA测试

     package tongji;
    import java.io.*;
    public class tongji {
    public static void main(String[] args)throws IOException
    {
    File f = new File("English.txt");
     FileInputStream fip = new FileInputStream(f);
         InputStreamReader reader = new InputStreamReader(fip, "UTF-8");
         StringBuffer sb = new StringBuffer();
         while (reader.ready()) {
             sb.append((char) reader.read());
         }
         System.out.println(sb.toString());
         reader.close();
         fip.close();
         int i;
         String A=sb.toString();
         String M="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
         char temp = 0;
         char NUM[]=new char[A.length()];
         char Z[]=new char[52];
         int X[]=new int[52];
         int MAX=0;
         Z=M.toCharArray();
         for(int k=0;k<52;k++)
         {
          X[k]=0;
         for(i=0;i<A.length();i++)
         {
          NUM[i]=A.charAt(i);
          if(Z[k]==NUM[i])
          {
          X[k]++;
          }
         }
         }
         for(i=1;i<52;i++)
         {
          MAX=X[0];
          if(X[i]>MAX)
          {
          MAX=X[i];
          }
         }
         for(i=0;i<52;i++)
         {
          if(X[i]==MAX)
          {
          temp=Z[i];
          }
         }
         System.out.println("这篇文章中英文字母个数分别为:");
         for(i=0;i<52;i++)
         {
         System.out.println(Z[i]+"字母个数为:"+X[i]);
         }
         File f1 = new File("abc.txt");
         FileOutputStream fop = new FileOutputStream(f1);
         OutputStreamWriter writer = new OutputStreamWriter(fop, "UTF-8");
         writer.append("该文章中出现最多的字母为:");
         writer.append(temp);
         writer.close();
         fop.close();
    }
    }
    仅仅可以从文件中读取英文,计算每个字母(A-Z)(a-z)的个数,并可以将最高频率的字母输出到文件中,但无法按题目要求查找最高频率的单词。
  • 相关阅读:
    (9)ASP.NET Core2.2 中的MVC路由二
    (8)ASP.NET Core2.2 中的MVC路由一
    (7)ASP.NET Core2.2 中的错误处理
    (6)ASP.NET Core2.2 中使用IHttpClientFactory发出HTTP请求
    (5)ASP.NET Core2.2 中的静态文件
    (4)ASP.NET Core2.2 中间件
    蒲公英 &#183; JELLY技术周刊 Vol.05: Rust & Electron 的高性能实践 -- Finda
    Taro 2.2 全面插件化,支持拓展和定制个性化功能
    使用 Taro 快速开发京东小程序
    技术周刊 · 0202 年了,你还不学一下 WASM 么?
  • 原文地址:https://www.cnblogs.com/jccjcc/p/9775166.html
Copyright © 2011-2022 走看看