HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

corejava-programming: Java program to check given number is Lychrel Number or not

If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 That is, 349 took three iterations to arrive at a palindrome. Although some numbers like 196, never produce a palindrome. A number that never forms a palindrome through the reverse and add process is called a Lychrel number. Write a java program to take a number and check whether it is a Lychrel number or not. If a number is not Lychrel then print the number of iterations that it took to produce a palindrome. If the number is Lychrel then print the 5th iteration NOTE: Check only till 10 iterations. If till 10 iterations you cannot find the palindrome then consider that number as Lychrel number. Use long datatype Sample Input: 47 Sample Output: 1 Sample Input: 349 Sample Output: 3 Sample Input: 196 Sample Output: 196 is a Lychrel Number 5th iteration of number 196 is 52514

corejava x 323
programming x 133
Posted On : 2017-07-09 14:22:26.0
profile hemana mana - hemana mana


import java.util.Scanner;

public class LychrelNumber {
public static void main(String[] args) {
Scanner input=new Scanner(;
long number=input.nextLong();
public static void checkLychrel(long input){
boolean result=true;
String fifthIterationResult=null;
Long temp=input;
for(int i=1;i<=10;i++){
if(temp==Integer.parseInt(new StringBuilder(temp.toString()).reverse().toString())){
}else if(i==5){
fifthIterationResult="5th iteration of number "+input+" is "+temp;
System.out.println(input+" is a Lychrel Number");

private static Long reverseAndAdd(Long number){
return number+Long.parseLong(new StringBuilder(number.toString()).reverse().toString());


Posted On : 2017-07-09 23:01:33
Are You Satisfied : 4 Yes  0 NO
profile Rishi Kumar - Rishi Kumar
Reply This Thread
thank you sir..but can this possible using array ?
profile Divesh - Divesh
19  0  0
Posted On :2017-07-11 17:14:42.0
Leave a Comment
Hi Divesh,
I think we can use array to get the reverse of a String, else if you want to store each iteration result in array, we can do that also, but i think it is not a good idea to consume more memory. Please check below code snippet


//return number+Long.parseLong(getReverse(number.toString()));

public static String getReverse(String input){
char[] charArray=input.toCharArray();
StringBuilder sb=new StringBuilder();
for(int i=charArray.length-1;i>=0;i--){
return sb.toString();
profile Rishi Kumar - Rishi Kumar
523  1847  17363
Posted On :2017-07-11 22:53:47.0
Leave a Comment

Post Answer
Please Login First to Post Answer: Login login with facebook -