-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP200.java
53 lines (39 loc) · 1.11 KB
/
P200.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package p200_299;
import java.util.Scanner;
//accepted
public class P200 {
static void dibujarArbol(int tabulaciones, int fibonacci){
for (int i = 0; i < tabulaciones; i++) {
System.out.print(" ");
}
if (fibonacci==0){
System.out.println(0);
} else if (fibonacci==1) {
System.out.println(1);
} else {
System.out.println(calcularFibonacci(fibonacci));
dibujarArbol(tabulaciones+1,fibonacci-2);
dibujarArbol(tabulaciones+1,fibonacci-1);
}
}
static int calcularFibonacci(int n) {
int resultado;
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
resultado = calcularFibonacci(n - 1) + calcularFibonacci(n - 2);
}
return resultado;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n>=0){
dibujarArbol(0,n);
System.out.println("====");
n = sc.nextInt();
}
}
}