I am sure that I'm the first one, but when I create a Java program:
Code:
it throws this error:
Code:
I am wondering how to fix it and why this is happening.
EDIT: This program was fixed by me. To anyone having this problem, you need to move
Code:
out of the while loop.
So the code will look like this:
Code:
Code:
public class Name
{
public static void main(String[] args)
{
int[] array;
array = new int[10];
int s=1;
while(thisistrue())
{
array[s]++;
s++;
}
}
}
it throws this error:
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
I am wondering how to fix it and why this is happening.
EDIT: This program was fixed by me. To anyone having this problem, you need to move
Code:
s++
out of the while loop.
So the code will look like this:
Code:
public class Name
{
public static void main(String[] args)
{
int[] array;
array = new int[10];
int s=1;
while(thisistrue())
{
array[s]++;
}
s++;
}
}