|
Palindrome Number
Verify whether a given number is Palindrome number.
|
package com.bethecoder.tutorials.coding.examples;
public class PalindromeNumberTest {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(isPalindrome(123456));
System.out.println(isPalindrome(1234321));
System.out.println(isPalindrome(1010));
System.out.println(isPalindrome(10101));
}
private static boolean isPalindrome(int num) {
return num == reverseNumber(num);
}
private static int reverseNumber(int num) {
int sum = 0;
while (num > 0) {
sum = (sum * 10) + (num % 10);
num = num/10;
}
return sum;
}
}
|
| |
It gives the following output,
false
true
false
true
|
|