java异常处理

  1. StringIndexOutOfBoundsException(index)

 

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3

public char charAt(int index) {
        if ((index < 0) || (index >= value.length)) {    //当这个索引小于0或者索引的长度大于等于字符串本身的长度 就会报错
            throw new StringIndexOutOfBoundsException(index);
        }
//发现这里索引是0到length;正确的应该是i<b.length

for(int i=0; i<=b.length();i++) {
            char s=b.charAt(i);
        
posted @ 2019-12-27 09:25  Tripple_Redddddddd  阅读(154)  评论(0)    收藏  举报