String index out of bounds exception java

前端 未结 3 1485
逝去的感伤
逝去的感伤 2020-11-29 12:43

I am getting the following error when calling a function from within my class: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 Although I used a sys

3条回答
  •  鱼传尺愫
    2020-11-29 13:46

    I think you need to change the looping condition which is the problem here. You are looping one more iteration when you do <=size and the index starts from i=0. You can change this

    for(int i=0; i<=size; i++)
    

    to

    for(int i=0; i

    and also take care about the inner loop condition.

提交回复
热议问题