我对文本文件有一些疑问:
我试图通过以下方式解决这个问题:
public class Aaasssssss {
public static void main(String[] args) throws IOException {
File file1 = new File("input.txt");
BufferedReader in = new BufferedReader (new FileReader (file1));
System.out.println("Letter Frequency");
int nextChar;
char ch;
int[] count = new int[30];
while ((nextChar = in.read()) != -1) {
ch = ((char) nextChar);
if (ch >= 'a' && ch <= 'z')
count[ch - 'a']++;
}
for (int i = 0; i < 26; i++) {
System.out.printf("%c %d", i + 'A' , count[i]);
System.out.println( "");
}
in.close();
}
}
我使用数组[30]为26个字母,1为(。运算符),1为空格,1为单词数,1为包机数