Created
April 7, 2012 05:10
-
-
Save ypxu/2325452 to your computer and use it in GitHub Desktop.
Palindrome Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PalindromeNumber { | |
public static boolean checkifPalindrome(int num) { | |
if (num < 0) { | |
return false; | |
} | |
int div = 1; | |
while (num / div >= 10) { | |
div = div * 10; | |
} | |
while (num > 0) { | |
int left = num / div; | |
int right = num % 10; | |
if (left != right) { | |
return false; | |
} | |
num = (num % div) / 10; | |
div = div / 100; | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
boolean result = PalindromeNumber.checkifPalindrome(0); | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment