//
//  Problem 3
//  by Pierre Grabolosa on 3/13/07.
//
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 num) 
   {
      // exit condition at num==0
      if  (num == 0)
         return 1;
      else 
      {
         // recursive call to catalan.
         return catalan (num - 1) * (4 * num - 2) / (num + 1);
      }
   }

   // the main function which is executed first when the program starts
   public static void main (String args[])
   {
      // display a header
      System.out.println("num  --> numth Catalan numumber");
      // from 0 to 10 included
      for(int i = 0; i <= 10; i++)
         System.out.println(""+ i + (i<10 ? " " : "") + " --> " + catalan(i));
   }
}
