Motzkin number | Java Program to find Nth Motzkin Number . ; Return the nth Motzkin Number . ; Base Case ; Recursive step ; driver code
import java . util . * ; class Digits { public static int motzkin ( int n ) { if ( n == 0 n == 1 ) return 1 ; return ( ( 2 * n + 1 ) * motzkin ( n - 1 ) + ( 3 * n - 3 ) * motzkin ( n - 2 ) ) / ( n + 2 ) ; } public static void main ( String [ ] args ) { int n = 8 ; System . out . print ( motzkin ( n ) ) ; } }