我正在练习字符串回文。我的 for 循环中的代码对吗?
public static void main (String args[])
{
String word = JOptionPane.showInputDialog("Input a String:");
String finalword = word.replaceAll(" ","").toLowerCase();
for (int x = word.length(); x >= word.length()-1; x--)
{
finalword.charAt(x);
}
if(word.equals(finalword))
{
JOptionPane.showMessageDialog(null, "Palindrome");
}
else
{
JOptionPane.showMessageDialog(null, "Not a Palindrome");
}
}
感谢你并致以真诚的问候。