/** * 題目描述: * 有這樣一類數字,他們順着看和倒着看是相同的數,例如:121,656,2332等,這樣的數字就稱為:回文數字。編寫一個函數,判斷某數字是否是回文數字。 * 要求實現方法: * public String isPalindrome(String strIn); * 【輸入】strIn: 整數,以字符串表示; * 【返回】true: 是回文數字; * false: 不是回文數字; * 【注意】只需要完成該函數功能算法,中間不需要有任何IO的輸入輸出 * @author Administrator * */ public class PalindromeNumber { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); System.out.println("請輸入數字:"); String strNum = scan.next(); boolean result = isPalindrome(strNum); System.out.println(result); } public static Boolean isPalindrome(String str){ boolean result=false; for(int i=0; i<str.length()/2;i++){ if(str.charAt(i) == str.charAt(str.length()-1-i)){ result=true; }else{ return result; } } return result; }