Check Whether Number is Palindrom

For Number:

private static boolean isPalindrome(int number){

int orignalNo = number;
int reverse = 0;
while(number != 0){
reverse = reverse*10 + number%10;
number = number/10;
}
return (orignalNo == reverse);
}

For String:

private static boolean isPalindrome(String pText){

for ( int i = pText.length() – 1; i >= 0; i– )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println(“Entered string is a palindrome.”);
else
System.out.println(“Entered string is not a palindrome.”);

References

http://javarevisited.blogspot.com/2012/12/how-to-check-if-number-is-palindrome-or-not-example.html

http://www.programmingsimplified.com/java/source-code/java-program-check-palindrome

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: