用java2. 回文数字:用户从键盘输入一个整数,程序将判断这个数是否是回文数。回文数是指将该数含有的数字逆序排列后得到的数和原数相同,例如12121、3223都是回文数。
时间: 2023-05-24 09:04:33 浏览: 109
java实现判断数字是否为回文数的程序
```
import java.util.Scanner;
public class PalindromeNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter an integer: ");
int number = scanner.nextInt();
if (isPalindromeNumber(number)) {
System.out.println(number + " is a palindrome number");
} else {
System.out.println(number + " is not a palindrome number");
}
scanner.close();
}
private static boolean isPalindromeNumber(int number) {
int reversedNumber = 0;
int remainder;
int originalNumber = number;
while (number > 0) {
remainder = number % 10; // Get the last digit
reversedNumber = reversedNumber * 10 + remainder; // Add the last digit to the reversed number
number = number / 10; // Remove the last digit from the original number
}
return originalNumber == reversedNumber;
}
}
```
阅读全文