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.”);
System.out.println(“Entered string is not a palindrome.”);



Leave a Reply

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

You are commenting using your 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: