//
//  Problem 3
//  by Pierre Grabolosa on 3/13/07.
//
import java.io.*;

public class problem3 {

	// the function has to be made static so it can be called from 'main'
	// without having to create an instance of problem3.
	public static int catalan (int N) {
		// exit condition at N==0
		if  (N == 0) {
			return 1;
		} else {
			// here the loop is done by calling the function again
			// this is what we call a recursive call.
			return catalan (N-1) * (4*N-2) / (N+1);
		}
	}

	// the main function which is executed first when the program starts
    public static void main (String args[]) throws java.io.IOException {
	
		// display a header
		System.out.println("N  --> Nth Catalan Number");
		// from 0 to 10 included
		for(int i = 0; i<= 10; i++)
			// display N -here i- and the associated catalan number
			// (i<10?" ":"") adds an extra space when i >= 10 so the
			// arrows keep being aligned.
			System.out.println(""+i+(i<10?" ":"")+" --> "+catalan(i));
	}
}
