Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 11

前端 未结 4 1585
别那么骄傲
别那么骄傲 2020-12-16 06:54

EVerytime I write any code similar to this one, I get this type of error. It\'s building a file but not letting it run, it just throws exception. I\'m not familiar with exce

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 07:18

    You should write the for cycle as

    for (int i = 0; i < name.length(); i++)
    

    The indexes in the strings are zero-based, as in the arrays, so they have a range from 0 to length - 1. You go to length, which is outside of bounds.

提交回复
热议问题