【发布时间】:2011-07-07 18:40:02
【问题描述】:
我是编程新手,在 Eclipse 中运行一些新代码时遇到了这个错误,完全迷失了。
import java.util.Scanner;
public class Lab6
{
public static void main(String[] args)
{
// Fill in the body according to the following comments
Scanner in= new Scanner(System.in);
// Input file name
String FileName=getFileName(in);
// Input number of students
int numOfStudents = FileIOHelper.getNumberOfStudents(FileName);
Student students[] = getStudents(numOfStudents);
// Input all student records and create Student array and
// integer array for total scores
int[]totalScores = new int[students.length];
for(int i=0; i< students.length; i++)
{
for(int j=1; j<4; j++)
{
totalScores[i]= totalScores[i]+students[i].getScore(j);
}
}
// Compute total scores and find students with lowest and
// highest total score
int i;
int maxIndex =0;
int minIndex =0;
for(i=0; i<students.length; i++);
{
if(totalScores[i]>=totalScores[maxIndex])
{
maxIndex=i;
}
else if(totalScores[i]<=totalScores[minIndex])
{
minIndex=i;
}
}
问题似乎在 if(totalScores[i]>=totalScores[maxIndex])
【问题讨论】:
-
堆栈跟踪的前几行(从您的 ArrayIndexOutOfBoundsException 开始)很关键。
-
代码中的另一个错误是 ;在 for() 之后。