-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASSIGNMENT_7.java
More file actions
31 lines (24 loc) · 924 Bytes
/
Copy pathASSIGNMENT_7.java
File metadata and controls
31 lines (24 loc) · 924 Bytes
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
import java.util.Scanner;
public class Assign7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input number
System.out.print("Enter a number: ");
int originalNumber = sc.nextInt();
int temp = originalNumber;
int reversedNumber = 0;
// Reverse the number
while (temp > 0) {
int digit = temp % 10; // Get the last digit
reversedNumber = (reversedNumber * 10) + digit; // Build reversed number
temp = temp / 10; // Remove the last digit
}
// Check for palindrome
if (originalNumber == reversedNumber) {
System.out.println(originalNumber + " is a Palindrome Number.");
} else {
System.out.println(originalNumber + " is Not a Palindrome Number.");
}
sc.close();
}
}