Home > programming > Check if an integer is palindrom

Check if an integer is palindrom


My solution. Checked.
recursive call.

public boolean ispalin(int x){
if(x == 0){
return true;
}else if(x < 0){
return false;
}else{
int digit = (int) Math.floor(Math.log10(x));
int pow = (int) Math.pow(10, digit);
int high = (int) Math.floor( x/ (pow));
int low = x % 10;

if(high == low){
return ispalin( (x-high*(pow))/10 );
}else{
return false;
}
}

}

Advertisements
Categories: programming
  1. No comments yet.
  1. No trackbacks yet.

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: