Program to print non square numbers | Java program to print first n non - square numbers . ; Print curr_count numbers . curr_count is current gap between two square numbers . ; skip a square number . ; Count of next non - square numbers is next even number . ; Driver code
import java . io . * ; import java . math . * ; class GFG { static void printNonSquare ( int n ) { int curr_count = 2 , num = 2 , count = 0 ; while ( count < n ) { for ( int i = 0 ; i < curr_count && count < n ; i ++ ) { System . out . print ( num + " ▁ " ) ; count ++ ; num ++ ; } num ++ ; curr_count += 2 ; } } public static void main ( String args [ ] ) { int n = 10 ; printNonSquare ( n ) ; } }