2024-06-14 05:57:38 +00:00
|
|
|
public class TestRecursion {
|
|
|
|
|
|
|
|
public int value = 0;
|
|
|
|
public TestRecursion child = null;
|
|
|
|
|
|
|
|
public TestRecursion(int n)
|
|
|
|
{
|
2024-06-17 17:25:24 +00:00
|
|
|
this.value = n;
|
2024-06-14 05:57:38 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|