判断回文算法代码简化至7行
问题:一串字符正序和倒序都相同为回文,请编写程序实现
源代码:
public class Palindrome {
public static void main(String args[]) {
String s1="apyeypa";
String s2=new StringBuffer(s1).reverse().toString();
System.out.println(s1.equals(s2)==true?"YES":"NO");
}
}
运行结果: