text: Nth non | Java program to find n - th non - square number . ; function to find the nth Non - Square Number ; conversion from int to long double is necessary in order to preserve decimal places after square root . ; calculating the result ; Driver code ; initializing the term number ; Print the result
code: import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static int findNthNonSquare ( int n ) { double x = ( double ) n ; double ans = x + Math . floor ( 0.5 + Math . sqrt ( x ) ) ; return ( int ) ans ; } public static void main ( String [ ] args ) { int n = 16 ; System . out . print ( " The ▁ " + n + " th ▁ Non - Square ▁ number ▁ is ▁ " ) ; System . out . print ( findNthNonSquare ( n ) ) ; } }