Reverse and Add Function | Java Program to implement reverse and add function ; Iterative function to reverse digits of num ; Function to check whether he number is palindrome or not ; Reverse and Add Function ; Reversing the digits of the number ; Adding the reversed number with the original ; Checking whether the number is palindrome or not ; Main method
public class ReverseAdd { long reversDigits ( long num ) { long rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } boolean isPalindrome ( long num ) { return ( reversDigits ( num ) == num ) ; } void ReverseandAdd ( long num ) { long rev_num = 0 ; while ( num <= 4294967295l ) { rev_num = reversDigits ( num ) ; num = num + rev_num ; if ( isPalindrome ( num ) ) { System . out . println ( num ) ; break ; } else if ( num > 4294967295l ) { System . out . println ( " No ▁ palindrome ▁ exist " ) ; } } } public static void main ( String [ ] args ) { ReverseAdd ob = new ReverseAdd ( ) ; ob . ReverseandAdd ( 195l ) ; ob . ReverseandAdd ( 265l ) ; } }