-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPalindromeNumber.java
More file actions
44 lines (31 loc) · 1.16 KB
/
Copy pathCheckPalindromeNumber.java
File metadata and controls
44 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
public class CheckPalindromeNumber {
public static void main(String[] args) {
int num;
// Create a Scanner object for user input
// Create a Scanner object for user input
Scanner in = new Scanner(System.in);
// Prompt the user for a positive integer
System.out.print("Input a positive integer: ");
// Read the integer entered by the user
int n = in.nextInt();
// Display a message to check if the number is a palindrome
System.out.printf("Is %d a palindrome number?\n", n);
// Check if the number is a palindrome and print the result
System.out.println(is_Palindrome(n));
}
// Function to reverse the digits of a number
public static int reverse_nums(int n) {
int reverse = 0;
while (n != 0) {
reverse *= 10;
reverse += n % 10;
n /= 10;
}
return reverse;
}
// Function to check if a number is a palindrome
public static boolean is_Palindrome(int n) {
return (n == reverse_nums(n));
}
}