题目
解答
解法一:
public static void main( String[] args ){
int s = -101;
Boolean i = isPalindrome(s);
System.out.println(i);
}
public static boolean isPalindrome(int x) {
if(x == 0){
return false;
}
String s = String.valueOf(x);
char[] chars = s.toCharArray();
char first = chars[0];
char end = chars[chars.length-1];
if(first == end){
return true;
}
return false;
}
解法二:
public static void main( String[] args ){
int s = -101;
boolean result = result(s);
System.out.println(result);
}
public static boolean result(int x){
if(x<0) return false;
int rem = 0;
int y = 0;
int quo = x;
while(quo != 0){
rem = quo % 10;
y = y * 10 + rem;
quo = quo / 10;
}
return y == x;
}