import java.util.Scanner;
public class Taxi {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int groups = input.nextInt();
int counter=0;
int[] pass = new int[groups];
for(int i=0; i<groups; i++){
pass[i] = input.nextInt();
}
for(int i=0; i<groups; i++){
if(pass[i]==4)
counter++;
else if(pass[i]+pass[i+1]<=4){
counter++;
i++;
}
else
counter++;
}
System.out.println(counter);
}
}
keep on receiving error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Taxi.main(Taxi.java:21)
please help