Check whether the number can be made perfect square after adding 1 | Java implementation of the approach ; Function that returns true if x is a perfect square ; Find floating point value of square root of x ; If square root is an integer ; Function that returns true if n is a sunny number ; If ( n + 1 ) is a perfect square ; Driver code
class GFG { static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static boolean isSunnyNum ( int n ) { if ( isPerfectSquare ( n + 1 ) ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 3 ; if ( isSunnyNum ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }