天天看點

Palindrome 回文數

回文數,從前到後,從後到前都一樣

把數字轉成字元串來處理

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 }      

繼續閱讀