数组索引越界字符数组中的异常

问题描述

在这代码中让数组索引越界 找不到我出错的地方

    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);

        }

    }
}

错误

Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 3

这是怎么回事!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...