0
我有這個代碼,但它不能計算分開的元素的頻率,而是不斷計算索引星數爲100.我怎樣才能得到分解元素的頻率。在java中計算數字和分配頻率
public class Grade {
public static void main(String[] args) {
int[] grade = {87, 68, 94, 100, 83, 78, 85, 96, 76, 87};
int[] frequency = new int[11];
for(int count=0; count< grade.length; count++) {
int d1 = grade[count]/10;
++frequency[d1];
for(int star=1; star<frequency.length; star++) {
System.out.printf("%4d%10d%n", star, frequency[star]);
}
}
}
這是明星和頻率[明星]結果
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 0,
7 - 0,
8 - 1,
9 - 0,
10- 0,
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 0,
8 - 1,
9 - 0,
10- 0,
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 0,
8 - 1,
9 - 1,
10- 0,
1 - 0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 0,
8 - 1,
9 - 1,
10- 1,
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 0,
8 - 2,
9 - 1,
10- 1,
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 1,
8 - 2,
9 - 1,
10- 1,
1 - 0,
2 -0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 1,
8 - 3,
9 - 1,
10- 1,
1 - 0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 1,
8 - 3,
9 - 2,
10- 1,
1 - 0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 2,
8 - 3,
9 - 2,
10 - 1,
1 -0,
2 - 0,
3 - 0,
4 - 0,
5 - 0,
6 - 1,
7 - 2,
8 - 4,
9 - 2,
10 - 1,
這個不清楚,你能提供你期望的輸出嗎?也許內層循環應該移到外層 – 2016-12-27 17:28:26