问题描述
限时送ChatGPT账号..我是 Java 新手,今天我开始研究数组,但我迷路了.我试图将一些值放入数组中,但出现错误 java.lang.ArrayIndexOutOfBoundsException
.
I am new to java and today I started to work on arrays and I'm lost. I am trying to put some values in an array but I'm getting the error java.lang.ArrayIndexOutOfBoundsException
.
这是我到目前为止所做的.
Here is what I have done so far.
int n=6;
int[]A= new int [1];
for(i=0;i<n;i++){
A[i]=keyboard.nextInt();
}
推荐答案
java.lang.ArrayIndexOutOfBoundsException 表示您正在尝试访问不存在的数组索引.
java.lang.ArrayIndexOutOfBoundsException means you are trying to access a array index that doesn't exist.
问题是您的数组大小为 1.但是,您将执行该循环六次.您可以使 n 等于 1,也可以增加数组的大小.
The problem is that your array is of size one.However, you are going through that loop six times. You can either make n equal to one, or increase the size of your array.
这篇关于java.lang.ArrayIndexOutOfBoundsException 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论