Generate a list of n consecutive composite numbers ( An interesting method ) | Java program to print n consecutive composite numbers ; function to find factorial of given number ; Prints n consecutive numbers . ; Driver program to test above function
class GFG { static long factorial ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { res *= i ; } return res ; } static void printNComposite ( int n ) { long fact = factorial ( n + 1 ) ; for ( int i = 2 ; i <= n + 1 ; ++ i ) { System . out . print ( fact + i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 4 ; printNComposite ( n ) ; } }