题目描述 判断一个正整数是不是回文数。 回文数的定义是,将这个数反转之后,得到的数仍然是同一个数。
public class Solution {
/**
* @SERLIN
*/
public static void main(String[] args) {
int n;
System.out.println(
"请输入一个整数:");
while (
true) {
Scanner InpuNum =
new Scanner(System.in);
n = InpuNum.nextInt();
if (isHuiWen(n)) {
System.out.println(n +
"是回文数!");
break;
}
else {
System.out.println(n +
"不是回文数!");
}
}
}
public static boolean isHuiWen(
int n) {
int m = reverse(n);
if (m == n) {
return true;
}
else {
return false;
}
}
public static int reverse(
int n) {
int temp =
0;
int j =
0;
temp = n;
while (temp !=
0) {
j = j *
10 + temp %
10;
temp /=
10;
}
return j;
}
}