28 lines
449 B
Java
28 lines
449 B
Java
public class TestRecursion {
|
|
|
|
public int value = 0;
|
|
public TestRecursion child = null;
|
|
|
|
public TestRecursion(int n)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|