Golomb sequence | Java Program to find first n terms of Golomb sequence . ; Return the nth element of Golomb sequence ; base case ; Recursive Step ; Print the first n term of Golomb Sequence ; Finding first n terms of Golomb Sequence . ; Driver Code
import java . util . * ; class GFG { public static int findGolomb ( int n ) { if ( n == 1 ) return 1 ; return 1 + findGolomb ( n - findGolomb ( findGolomb ( n - 1 ) ) ) ; } public static void printGolomb ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( findGolomb ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 9 ; printGolomb ( n ) ; } }