for (int i = 0; i <= (line.length()/2); i++) { \\loops from the first character until the character in the middle
if (line.charAt(i) != line.charAt(line.length() - i)) { \\checks if 1st character of line is not equal to the last character, and so on..
System.out.println("Entered string is not a palindrome.");
return; \\ends program, no need to check anything else
}
}
System.out.println("Entered string is a palindrome.");
我不斷收到一個索引超出範圍的錯誤檢查字符串是迴文
你有沒有谷歌錯誤,努力瞭解它是什麼以及爲什麼發生? – tnw 2014-10-06 19:16:22
你的第一步應該是看看這意味着什麼。 – krillgar 2014-10-06 19:16:24
在紙上做這個計算(記住索引從0開始)。 – Pshemo 2014-10-06 19:16:37