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/