Skip to content

Instantly share code, notes, and snippets.

@ypxu
Created April 7, 2012 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypxu/2325452 to your computer and use it in GitHub Desktop.
Save ypxu/2325452 to your computer and use it in GitHub Desktop.
Palindrome Number
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