java异常处理
- 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);

浙公网安备 33010602011771号