Find all divisors of first N natural numbers | Java implementation to find all the divisors of the first N natural numbers ; Function to find the factors of the numbers from 1 to N ; Loop to find the factors of the first N natural numbers of the integer ; Driver Code
import java . util . * ; class GFG { static void factors ( int n ) { int i , j ; System . out . print ( "1 -->1NEW_LINE"); for ( i = 2 ; i <= n ; i ++ ) { System . out . print ( i + " ▁ - - > " ) ; for ( j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { System . out . print ( j + " , ▁ " ) ; if ( i / j != j ) System . out . print ( i / j + " , ▁ " ) ; } } System . out . print ( "NEW_LINE"); } } public static void main ( String args [ ] ) { int n = 5 ; factors ( n ) ; } }