回文数,从前到后,从后到前都一样
把数字转成字符串来处理
1 package com.rust.cal; 2 3 public class Palindrome { 4 public static boolean isPalindrome(int x) { 5 String s = String.valueOf(x); 6 String revers = new StringBuffer(s).reverse().toString(); 7 if (s.equalsIgnoreCase(revers)) { 8 return true; 9 } 10 return false; 11 } 12 13 public static void main(String arg[]){ 14 int input = 123; 15 if (isPalindrome(input)) { 16 System.out.println("Yes"); 17 } else { 18 System.out.println("NO"); 19 } 20 } 21 }