Привет, нужно посчитать количество цифр в массиве идущих подряд. Почему у меня ошибка что я выхожу за пределы массива ?? помогите пожалуйста, спасибо
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
int[] array = new int[]{2,4,1,2};
int n = 4;
int count = 0, sum = 0 ;
for (int i = 0 ; i < n; i++)
{
int j =i;
while(array[j] % 2 == 0 && j < n)
{
count++;
j++;
}
if(sum < count)
{
sum = count;
}
count = 0;
}
System.out.println(sum);
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for
length 4
at Main.main(Main.java:14)