9. Palindrome Number


public class Palindrome_Number9 {
public static boolean isPalindrome(int x) {
if(x<0){
return false;
}
String result=new Integer(x).toString();


for(int i=result.length()/2-1;i>=0;i--){
if(result.charAt(i)!=result.charAt(result.length()-i-1)){
return false;
}
}

return true;

/*
public boolean isPalindrome(int x) {
if (x < 0) return false;
if (x < 10) return true;
int y = x, result = 0;
while (y > 0){
result = result*10 + y % 10;
y = y/10;
}
return result == x;
}
*/
}

public static void main(String[] args) {

System.out.println(isPalindrome(1) );

}
}
 
原文地址:https://www.cnblogs.com/cstxx77/p/13060471.html