回文数,从前到后,从后到前都一样
把数字转成字符串来处理
package com.rust.cal; public class Palindrome { public static boolean isPalindrome(int x) { String s = String.valueOf(x); String revers = new StringBuffer(s).reverse().toString(); if (s.equalsIgnoreCase(revers)) { return true; } return false; } public static void main(String arg[]){ int input = 123; if (isPalindrome(input)) { System.out.println("Yes"); } else { System.out.println("NO"); } } }