又见回文 (SDUT 2560)

 

 

package leslie1;
 
//import java.io.*;
//import java.math.*;
//import java.text.*;
//import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while (cin.hasNextLine()) {
			String a = cin.nextLine();
			if (a.equals("2013")) //注意这里不要用'a=="2013"',而两者内存中的地址不同,会导致比较出错,应该用'a.equals("2013")'(equals是按字符串内容比较)
				break;
			else {
				a = a.replaceAll(" +", "");//正则表达式去除空格
				StringBuffer b = new StringBuffer(a);
				b.reverse();
				String c = new String(b);
				if (a.equals(c))
					System.out.println("YES");
				else
					System.out.println("NO");
			}
		}
		cin.close();
	}
}

  转载于 https://blog.csdn.net/wzy_2017/article/details/79981861

posted @ 2020-12-16 19:15  vkd  阅读(88)  评论(0编辑  收藏  举报