String index out of bounds? (Java, substring loop)

前端 未结 5 584
感情败类
感情败类 2021-01-20 17:26

This program I\'m making for a COSC course isn\'t compiling right, I keep getting the error:

Exception in thread \"main\" java.lang.StringIndexOutOfBoundsException:

5条回答
  •  悲&欢浪女
    2021-01-20 18:29

    Removing the equal sign should fix that.

    while (count < input.length()) {

    and since you want to get a single character, you should do this:

    substr(count,1)

    because the 2nd parameter is actually length, not index.

提交回复
热议问题