forked from sat5297/hacktober-coding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome.java
32 lines (30 loc) · 877 Bytes
/
Palindrome.java
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
import java.util.*;
public class Palindrome
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number which needs to be checked for palindrome");
int n = sc.nextInt();
int rev =0;
/*Store actual value of number in num as n will be changed in the loop */
int num = n;
/*Loop exists till the whole number doesn't become 0 */
while(n != 0)
{
int rem = n%10;
rev = rev*10 + rem;
n = n/10;
}
/*Compare the original number and reverse of the number */
if(num == rev)
{
System.out.println("Palindrome");
}
else
{
System.out.println("Not Palindrome");
}
sc.close();
}
}