📄 te.java
字号:
import java.io.*;
public class te{
private String words;
public te(String input)
{
words = input.toString();;
}
public int getNum()//return the lenth of the .txt file
{
return words.length();
}
public int result(char c)//calculate how many times the character c show up
{
String temp=new String(words);
int index=temp.indexOf(c);
int n=0;
while(index>=0)
{
temp=temp.substring(index+1,temp.length());
index=temp.indexOf(c);
n++;
}
return n;
}
public static void main(String[] args)throws IOException{
BufferedReader buf;//file place
buf=new BufferedReader(new InputStreamReader(System.in));
String fileinput;
System.out.println("Please input the place where your file is:");;
String strtotal="";
try{
fileinput=buf.readLine();
if(fileinput.equals("quit"))System.exit(0);
System.out.println();
File file=new File(fileinput);
FileReader fr=new FileReader(file);
LineNumberReader in=new LineNumberReader(fr);
int n=(int)file.length();
in.mark(n);
in.skip(n);
int k=in.getLineNumber();
in.reset();
String str;
while((str=in.readLine())!=null){
System.out.println(str);
strtotal+=str;
}
in.close();
}catch(IOException e){
System.out.println(e);
} //get the file's words
te word=new te(strtotal);
int[] num = new int[150]; //define the num to load characters
int i;
char ch='A';
for (i=0;ch<150;ch++,i++) //calculate the times of every characters show up
num[i]=word.result(ch);
System.out.println("The number of the characters is : "+word.getNum()); //output the length
for (i=0,ch='A';i<70;ch++,i++) //output the letters and their times
System.out.println("The num "+ch+" has presented : "+num[i]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -