In: Computer Science
For the following Ackerman function defined for non-negative
integers, write a Java program that:
Contains a method called computeAckermann that takes two integer
values as parameters and calculates and returns the value of the
Ackerman function. The method should be defined inside a class
named Ackermann.
Test the implementation of Ackerman in (a) by calling it from main
function and printing the returned value. The main function should
be defined in a separate class named AckermannDemo.
class Ackermann
{
public int computeAckermaan(int m,int n)
{
if (m == 0)
{
return n + 1;
}
else if(n==0)
{
return computeAckermaan(m - 1, 1);
}
else
{
return computeAckermaan(m-1,computeAckermaan(m,n-1));
}
}
};
public class AckermannDemo{
public static void main(String args[])
{
Ackermann obj=new
Ackermann();
System.out.println("Ackermaan value:
" + obj.computeAckermaan(3,4));
}
}