while True:
s=input("请输入字符串:")
s1=s[::-1]
if s1==s:
print("是回文")
else:
print("不是回文")
package huiwen;
import java.util.Scanner;
public class Homework_Huiwen {
public static void main(String[] args) {
while (true) {
System.out.println("请输入字符:");
String s = new Scanner(System.in).nextLine();
if (huiwen(s)) {
System.out.println("是回文");
break;
}else {
System.out.println("不是回文");
}
}
}
private static boolean huiwen(String s) {
for (int i = 0,j=s.length()-1; i<j; i++,j--) {
if (s.charAt(i)!=s.charAt(j)) {
return false;
}
}
return true;
}
}