/*
* 输入一个五位数判断是不是回文数。即12321是回文数,有能力同学试试看判断判断任意一个正数是不是回文数。
*/
public class Test08 {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
System.out.print("请判断该数字是否是回文数字: ");
long num = input.nextLong();
System.out.print("该数字是否是回文数字?: " + ifPalindromicNumber(num));
}
public static long palindromicNumber (long num) {
long temp = 0;
while (num != 0) {
temp *= 10;
temp += num % 10;
num /= 10;
}
return temp;
}
public static boolean ifPalindromicNumber (long num) {
long temp = palindromicNumber (num);
if (temp == num) {
return true;
} else {
return false;
}
}
}
输入一个五位数判断是不是回文数
最新推荐文章于 2023-04-02 14:15:00 发布