回數:從左向右讀和從右向左讀的結果時一樣的,這樣的解釋比較通俗。
代碼如下所示:
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一起交流。