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();
}
}
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)的个数,并可以将最高频率的字母输出到文件中,但无法按题目要求查找最高频率的单词。