Lychrel Number Implementation | Java Program to check whether the given number is Lychrel Number or not with given limit on number of iterations . ; Max Iterations ; Function to check whether number is Lychrel Number ; Function to check whether the number is Palindrome ; Function to reverse the number ; driver program
import java . io . * ; public class LychrelNumberTest { private static int MAX_ITERATIONS = 20 ; private static boolean isLychrel ( long number ) { for ( int i = 0 ; i < MAX_ITERATIONS ; i ++ ) { number = number + reverse ( number ) ; if ( isPalindrome ( number ) ) return false ; } return true ; } private static boolean isPalindrome ( final long number ) { return number == reverse ( number ) ; } private static long reverse ( long number ) { long reverse = 0 ; while ( number > 0 ) { long remainder = number % 10 ; reverse = ( reverse * 10 ) + remainder ; number = number / 10 ; } return reverse ; } public static void main ( String [ ] args ) { long number = 295 ; System . out . println ( number + " ▁ is ▁ lychrel ? ▁ " + isLychrel ( number ) ) ; } }