我有一个程序可以对字母在故事中出现的次数进行排序和计数。我遇到的一个问题是我需要打印这封信以及它在排序时出现的次数。
if (line == null) break; //check for end of file before doing anything
line=line.toLowerCase();
for (int i = 0 ; i < line.length(); i++ ) {
letter = line.charAt(i);
int num = (int)letter;
num-=96;
if(num>=1 && num<=26) alpha[num]++;
}
for(int j=1; j<=26; j++) System.out.println((char)(j+64) +" = "+alpha[j]);
int[] minArr = new int[6];
int[] maxArr = new int[6];
Arrays.sort(alpha);
// System.out.print("There are "+max+" and "+min);
for(int n=1;n<=5;n++) {
System.out.println("is the highest with "+alpha[alpha.length-n]);
System.out.println("is the lowest with "+alpha[n]);
// int max = alpha.length-n;
// System.out.println((char)(min+64)+" has the least number of letters"
}
有没有办法让我得到排序后的字母和它们的值?