简单题 回文数判断 121 313 即为回文数 代码如下:
public boolean isPalindrome(int x) {
String s = String.valueOf(x);
StringBuilder stringBuilder = new StringBuilder(s);
String s1 = stringBuilder.reverse().toString();
if (s1.equals(s)) {
return true;
} else return false;
}
一行简写
public boolean isPalindrome2(int x) {
return Integer.toString(x).equals(new StringBuilder(String.valueOf(x)).reverse().toString());
}