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) );

}
}
 

 

posted @ 2020-06-07 14:18  lalalalatxx  阅读(106)  评论(0编辑  收藏  举报