1 import java.util.Scanner; 2 /** 3 * @author 冰樱梦 4 * 时间:2018年下半年 5 * 题目:回文数 6 * 7 */ 8 public class Exercise06_03 { 9 public static void main(String[] args){ 10 Scanner input=new Scanner(System.in); 11 System.out.println("输入一个整数: "); 12 int number=input.nextInt(); 13 if(isPalindrome(number)) System.out.println(number + "是回文数"); 14 else System.out.println(number + "不是回文数"); 15 } 16 public static int reverse(int number){ 17 int a=1,sum=0,b=0,s=0; 18 int l = (number+" ").length()-1; 19 for(int i=1;i<=l;i++){ 20 sum=(int)(number/(Math.pow(10, l-a))); 21 number=(int) (number%(Math.pow(10, l-a))); 22 s+=sum*(Math.pow(10, b)); 23 b++; 24 a++; 25 } 26 return s; 27 } 28 public static boolean isPalindrome(int number){ 29 if(number==reverse(number)) return true; 30 else return false; 31 } 32 }