Program to print non square numbers | Java program to print first n non - square numbers . ; Function to check perfect square ; function to print all non square number ; variable which stores the count ; not perfect square ; Driver code
import java . io . * ; import java . math . * ; class GFG { static boolean isPerfectSquare ( int n ) { if ( n < 0 ) return false ; int root = Math . round ( ( int ) ( Math . sqrt ( n ) ) ) ; return n == root * root ; } static void printnonsquare ( int n ) { int count = 0 ; for ( int i = 1 ; count < n ; ++ i ) { if ( ! isPerfectSquare ( i ) ) { System . out . print ( i + " ▁ " ) ; count ++ ; } } } public static void main ( String args [ ] ) { int n = 10 ; printnonsquare ( n ) ; } }