の要素の最小値と最大値を決定するために、StudentScore
クラスのgetScore()
メソッドを呼び出そうとしています。printStat()
。私はArrayIndexOutOfBoundException
を得ています。それはどういう意味ですか、どうすれば問題を解決できますか?オブジェクトのArraylistで分を検索すると、arraylistの要素を比較できません
public class ScoreCalculator{
private int[] scoreCounter;
ArrayList<StudentScore> scores ;
public ScoreCalculator(int maxScore) {
scoreCounter = new int[maxScore];
scores = new ArrayList<StudentScore>(maxScore);
}
public void printStat() {
System.out.println("Score Report for " + scores.size() + " Students ");
min = 0;
max = 0;
int j=0;
for (j = 0; j < scores.size(); j++) {
if (scores.get(j).getScore() < scores.get(j - 1).getScore()) {
min = scores.get(j).getScore();
}
if (scores.get(j).getScore() > scores.get(j - 1).getScore()) {
max = scores.get(j).getScore();
}
}
System.out.println(min);
System.out.println(max);
}
'J-1 'あなたのコード内で負になることができ、インデックス範囲は、0(サイズです)-1、負の値は、あなたが要素' J-1'にアクセス – haifzhan
許可されていません。あなたのリストを注文することをお勧めします。最初の要素は 'min'で、最後の要素は' max'です。 –