Non | Java program to count number of ways to connect n ( wheren is even ) points on a circle such that no two connecting lines cross each other and every point is connected with one other point . ; A dynamic programming based function to find nth Catalan number ; Table to store results of subproblems ; Initialize first two values in table ; Fill entries in catalan [ ] using recursive formula ; Return last entry ; Returns count of ways to connect n points on a circle such that no two connecting lines cross each other and every point is connected with one other point . ; Throw error if n is odd ; Else return n / 2 'th  Catalan number ; Driver Code
import java . io . * ; class GFG { static int catalanDP ( int n ) { int [ ] catalan = new int [ n + 1 ] ; catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( int j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } static int countWays ( int n ) { if ( n < 1 ) { System . out . println ( " Invalid " ) ; return 0 ; } return catalanDP ( n / 2 ) ; } public static void main ( String [ ] args ) { System . out . println ( countWays ( 6 ) + " ▁ " ) ; } }