“`
package com.imooc;
import java.util.Scanner;
public class huiWen {
/**
* @param args
* 用栈来判断是否是回文,中点以前压入栈,然后再出站一一和中点以后的进行对比,若都相等,出站完毕
* 为回文,否则为否
*/
public static void main(String[] args) {
char[] a;
myStack stack=new myStack();
int mid=0;
int next;
Scanner scanner=new Scanner(System.in);
a=scanner.nextLine().toCharArray();//将String类型转换为char类型
mid=a.length/2-1;//求出字符串中点
stack.CreateQueue(100);
for(int i=0;i<=mid;i++){
stack.EnStack(a[i]);
}
if(a.length%2==0){
next=mid+2;
}
if(a.length%2!=0){
next=mid+1;
}
for(int i=mid;i<a.length;i++){
if(a[i]!=stack.DeStack()){
break;
}
}
if(stack.StackEmpty()){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
“`