forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
28 lines (24 loc) · 793 Bytes
/
Palindrome.java
File metadata and controls
28 lines (24 loc) · 793 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
/* A Palindrome number is a number that remains unchanged when reversed.
EXAMPLE:
121 is a palindrome because its reverse ie '121' is same as the original number.
123 is NOT a palindrome because its reverse i.e. '321' is not same as the original number '123'.
*/
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int copy = n;
int r = 0, d = 0;
while (n > 0) {
d = n % 10;
r = 10 * r + d;
n = n / 10;
}
if (r == copy) {
System.out.println(copy + " is a palindrome number");
} else {
System.out.println(copy + " is not a palindrome number");
}
}
}