Write a program to check a no whether it is a palindrome or not … USING WHILE LOOP.
import
java.io.*;
class
Palindrome
{
public
static
void
main()
throws
IOException
{
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(System.in));
System.out.print(
"Enter a number : "
);
int
n = Integer.parseInt(br.readLine());
int
rev =
0
, a = n, d =
0
;
while
( a>
0
)
{
d = a %
10
;
rev = rev *
10
+ d;
a = a /
10
;
}
if
( rev == n)
System.out.println(
"The number is a Palindrome"
);
else
System.out.println(
"The number is NOT a Palindrome"
);
}
}
No comments:
Post a Comment