【发布时间】:2013-01-30 03:59:34
【问题描述】:
我遇到了这个有趣的ArrayIndexOutofBounds 异常。
代码是这样的:
int m = 0;
while (scan.hasNextInt())
{
intArray[m++] = scan.NextInt();
}
我只是将一堆整数扫描到一个数组中,但我总是收到ArrayIndexOutofBounds 错误。我以为我的int m 已经初始化为零了?
谢谢
【问题讨论】:
-
你初始化 intArray 了吗?
-
是的,我确实像这样初始化了我的数组:
int[] intArray = new int[inputString.length()];其中 inputString 是我正在扫描整数的字符串。 -
在定义数组之前
System.out.println(inputString.length());会得到什么? -
附注我假设你的意思是
nextInt因为NextInt不会编译。