“java.lang.arrayIndexoutofboundSexception” Code-Antworten

java.lang.arrayIndexoutofboundSexception

import java.util.Random;
public class demo{
  public static void main(String[]args){
    Random rand=new Random();
    int array[]=new int[10];
    for(int i=0;i<array.length;i++){
      array[i]=rand.nextInt(100);//random between 0 and 100
    }
    System.out.println(array[array.length]);// error java.lang.ArrayIndexOutOfBoundsException
    // because index start 0 and end array.length
  }

}
Itchy Iguana

ArrayIndexoutOfBoundSexception

class AccessArrayOutsie
{
    public static void main (String[] args)
    {
        int[] array = new int[3];
        array[0] = 3;
        array[1] = 5;
  	array[2] = 6;
 
        for (int i = 0; i <= array.length; i++)
            System.out.println(array[i]);
    }
}
Outrageous Ostrich

Ähnliche Antworten wie “java.lang.arrayIndexoutofboundSexception”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen