MiniJavaCompiler/Test/JavaSources/TestRecursion.java

35 lines
638 B
Java

public class TestRecursion {
public int value = 0;
public TestRecursion child = null;
public TestRecursion(int n)
{
this.value = n;
if(n > 0)
{
child = new TestRecursion(n - 1);
}
}
public int fibonacci(int n)
{
if(n < 2)
{
return n;
}
else
{
return fibonacci(n - 1) + this.fibonacci(n - 2);
}
}
public int ackermann(int m, int n)
{
if (m == 0) return n + 1;
if (n == 0) return ackermann(m - 1, 1);
return ackermann(m - 1, ackermann(m, n - 1));
}
}