I am getting the Array index out of bounds in this code cant find where i am getting wrong
public static void main(String[] args) {
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String s=sc.next();
int count=0;
char[] str=s.toCharArray();
for(int i=0;i<str.length;i++){
if(str[i]=='1' && str[i+ 1]!='1'){
count++;
}
}
System.out.println(count);
}
}
}
error :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
What's wrong with this !!