Rare Numbers | Java implementation to check if N is a Rare number ; Iterative function to reverse digits of num ; Function to check if N is perfect square ; Find floating point value of square root of x . ; If square root is an integer ; Function to check if N is an Rare number ; Find reverse of N ; Number should be non - palindromic ; Driver code
class GFG { static int reversDigits ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static boolean isRare ( int N ) { int reverseN = reversDigits ( N ) ; if ( reverseN == N ) return false ; return isPerfectSquare ( N + reverseN ) && isPerfectSquare ( N - reverseN ) ; } public static void main ( String [ ] args ) { int n = 65 ; if ( isRare ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }