我的问题发生在for循环中,以便将文件中的值读入我的分数数组中。该程序读入并打印前6个值或2行的整数,但然后我得到ArrayIndexOutOfBoundsException:2将整数读入多维数组
我不知道为什么这是停在那里。如果我有j < 1000,它会读取17个值。无论如何,我正在阅读的文件在下面(不知道文本文件的格式)。
任何帮助,将不胜感激
Andy Matt Tom
3 2 3
4 4 5
3 3 2
2 2 2
2 4 2
2 3 2
4 4 5
2 3 3
4 3 5
3 3 6
2 2 5
3 3 3
3 3 2
3 2 4
3 2 6
3 4 3
2 3 2
2 2 2
50 52 62
public static void main(String args[])
{
try
{
if (args.length<1)
{
System.out.printf("\n...You must enter the name of a file\n");
System.exit(0);
}
Scanner infile = new Scanner (new File(args[0]));
int par= 3;
int play= 18;
String[] players= new String[play];
int k=0;
int scores[][]= new int[play-1][par-1];
while(infile.hasNext())
{
players[k]=infile.next();
k++;
if (k==play)
break;
}
for(int j=0; j<par; j++)
{
for (int i=0; i<play; i++)
{
scores[j][i]=infile.nextInt();
System.out.println(scores[j][i]);
}
}
}
catch (FileNotFoundException e)
{
System.out.println("Bug");
System.exit(0);
}
}
非常感谢,我不知道我在想什么-1 – mju516 2012-03-11 21:02:30