58) Write a program to input a number and check whether it is Lychrel number or not? (56 its reverse 65, 56+65=121 is a palindrome Number so it is Lychrel Number.)
import java.util.*;
public class Lychrel
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number");
int a = sc.nextInt();
int k = a;
int r = 0;
while(k>0)
{
int d = k%10;
r=(r*10)+d;
k=k/10;
}
int p = a+r;
int m = 0;
while(p>0)
{
int d = p%10;
m=(m*10)+d;
p=p/10;
}
if(m==a+r)
{
System.out.println("Entered number is a LYCHREL Number ");
}
else
{
System.out.println("Entered number is not a LYCHREL Number ");
}
}
}
Output :
|
lychrel-number
|
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal