String index out of range: n

后端 未结 3 567
深忆病人
深忆病人 2021-01-26 16:55

Im having a bit of a problem with this code each time i execute it it gives me an error String index out of range: \'n\' n - is the no. of characters that is entered in the tex

3条回答
  •  执念已碎
    2021-01-26 17:12

    Use <, not <= when iterating over the string. With <=, you get an out of bounds error, when j equals the length of the string. Remember that characters in the string are indexed starting from zero.

    for(int j = 0; j < b.length(); j++)
    

提交回复
热议问题