对于字符串
HACK,我们有一个
.length的
4。Java中的索引从0开始,所以我们有
['H','A','C','K'] ^ ^ ^ ^ 0 1 2 3
所以让我们在while循环中说
i=4
while (i <= arrNumberSequence.length)while (is 4 less than or equal to 4? yes 4==4 so continue with the loop)
当我们尝试访问时,
charAt(4)它不是我们字符串的有效索引
['H','A','C','K'] ^ ^ ^ ^ ^ 0 1 2 3 4
所以我们得到了例外
java.lang.StringIndexOutOfBoundsException: String index out of range: 4



