One way is to flip the current number first, and then compare it with the original number (omitted)
Another method is recursion. It uses a copy number to recursion the original number to flip it, And then compares it with the copy number.
Package recursion; public class check_if_a_number_is_palindrome {public static void main (string [] ARGs) {int num = 121321; system. out. println (check (Num); num = 12321; system. out. println (check (Num); num = 123321; system. out. println (check (Num);} // One method is to flip the current number first, and then compare it with the original number (omitted) // The other method is the recursive method static int dupnum; public static Boolean check (INT num) {dupnum = num; // copy the original number return Rec (Num );} public static Boolean Rec (in T num) {If (issingledigit (Num) {return num = dupnum % 10;} // recursively causes num: 121-> 12-> 1 is equivalent to comparing if (! Rec (Num/10) {// if the previous comparison has failed, you do not need to continue to compare return false;} else {dupnum/= 10; return num % 10 = dupnum % 10; // compare the last digit of the original number with the last digit of the recursive number} // helper function: determines whether it is a single-digit public static Boolean issingledigit (INT num) {If (Num >=0 & num <10) {return true;} else {return false ;}}}
Http://www.geeksforgeeks.org/check-if-a-number-is-palindrome/