且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么java.lang.ArrayIndexOutOfBoundsException意思?

更新时间:2022-11-16 15:14:34

java.lang.ArrayIndexOutOfBoundsException意味着你试图访问不存在的数组索引。

问题是,你的数组大小one.However的,你是通过循环六次去。您可以从N等于一体,或增加您的数组的大小。

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 means you are trying to access a array index that doesn't exist.

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.