public class reverse
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a new string : ");
String word = sc.nextLine();
StringBuilder s = new StringBuilder();
for (int i = 0; i <= word.length() - 1; i++)
{
char c = word.charAt(word.length() - i - 1);
s.append(c);
}
System.out.println("Reversed String = " + s);
if (word.equals(s))
{
System.out.println("This is a palindrome");
}
else
{
System.out.println("This is not a palindrome");
}
}
}
无论我输入什么字符串,这总是打印“这不是回文”