我不确定为什么会收到此错误。该代码旨在测试回文而不考虑标点符号。
所以这是我的代码:
char junk;
String temp = "";
for (int i = 0; i < txt.length(); i++)
{
junk = txt.charAt(i);
if (Character.isLetterOrDigit(txt.charAt(jumk)))
{
temp += junk;
}
}
txt = temp;
left = 0;
right = txt.length() -1;
while (txt.charAt(left) == txt.charAt(right) && right > left)
{
left++;
right--;
}
java.lang.StringIndexOutOfBoundException: PalindromeTester.main(PalindromeTester.java:35) 处的字符串索引超出范围 0
第35行如下:
while (txt.charAt(left) == txt.charAt(right) && right > left)