public static Boolean isHuiWen(String input){
Boolean flag=true;
int length=input.length();
for (int i=0;i<length/2;i++){
if (input.toCharArray()[i]!=input.toCharArray()[length-1-i]){
flag=false;
}
}
return flag;
}
public static void main(String[] args) {
Scanner stu=new Scanner(System.in);
System.out.println("请输入数据:");
String sName=stu.next(); //next()方法用来接收控制台输入的字符串
Boolean flag= isHuiWen(sName);
System.out.println("输入的数据是否为回文"+flag);
}
运行结果: