1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
|
public static int fibonacci(int n, int depth)
{
for(int i = 0; i < depth; i++) {
System.out.print(" ");
}
System.out.println(n);
if (n==0)
return 0;
if (n==1)
return 1;
if (n>1)
return fibonacci(n-1, depth+1)+fibonacci(n-2, depth+1);
else return 0;
}
} |