回数:从左向右读和从右向左读的结果时一样的,这样的解释比较通俗。
代码如下所示:
public class isPalindrome {
public static boolean isPalindrome(int x) {
int z=x;
if(z<0){
return false;
}
int temp=0;
while(z!=0){
int y = z%10;
temp = temp*10+y;
z=z/10;
}
if( temp > Integer.MAX_VALUE || temp < Integer.MIN_VALUE)
return false;
if(x==temp){
return true;
}else{
return false;
}
}
public static void main(String[] args) {
int x= 12321;
boolean b= isPalindrome.isPalindrome(x);
System.out.println(b);
}
}
如果您有更好的解决方案,请加QQ群691761026一起交流。