I am trying to create a array with Java that can hold as many numbers as the index 'i' is big.
for (int i = 0; i <= 10; i++)
{
int[] zahlenListe = new int[i];
zahlenListe[i] = i + 5;
System.out.println(zahlenListe[i]);
}
but I am always getting the error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Start.main(Start.java:27)
Java:27 is this line of code: zahlenListe[i] = i + 5;.
But everything is working fine when I change this line
int[] zahlenListe = new int[i];
to this:
int[] zahlenListe = new int[11];
Anybody cares to explain where the error is?