//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.14 on page 86
//  Recursive Ackermann  function

public class Pr0414
{ public static void main(String[] args)
  { for ( int m = 0 ; m < 4 ; m++ )
    {  for ( int n = 0 ; n < 4 ; n++ )
         System.out.print("ack("+m+","+n+") = " 
              + ackermann(m,n) + "   ");
       System.out.println() ;
    }
  } 
  public static int ackermann(int m, int n)
  {  if (m == 0) return 1 ;       // basis
     if (n==0)             
       if (m==1) return 2 ;       // basis
       else return m + 2 ;        // basis
     int ackM = ackermann(m-1,n) ;
     return ackermann(ackM, n-1); // recursion
  }
}
