当我使用这种编码获取用户输入时,我得到了债券错误。 noOfJudges
的用户输入是数组的长度。对于每一个法官进入和测试,看它是否是1到10之间 代码
得分:为什么我得到这个“超出界限”的错误?
double [] scores = new double [noOfJudges];
System.out.print("Please enter the next score: ");
for(scoreEntry = 0; scoreEntry < scores.length; scoreEntry++)
scores[scoreEntry]=console.nextDouble();
System.out.println();
while((scores[scoreEntry] < MIN_SCORE)||(scores[scoreEntry] > MAX_SCORE))
{
System.out.print("Please reenter the score (must be between 1.0 and 10.0, in .5 increments): ");
scores[scoreEntry] = console.nextDouble();
System.out.println();
}
如果有人想完全很大,有没有办法来检查,看是否有号码是介于1到10之间,只有5个增量?
从我可以告诉,你得到的OutOfBoundsException因为你scoreEntry元素尚未您最初的循环后复位。当您在while循环中调用分数[scoreEntry]时,该值大于score.length并超出界限。 – kamran619 2013-04-27 02:42:55