- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFibonacciExample.java
More file actions
Latest commit
32 lines (28 loc) · 762 Bytes
/
Copy pathFibonacciExample.java
File metadata and controls
32 lines (28 loc) · 762 Bytes
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
packagecom.codinginterview;
publicclassFibonacciExample {
publicstaticvoidmain(String[] args) {
System.out.println("Fibonacci Sequence Example");
printFibonacciSeq(10);
System.out.println();
for (inti = 0; i < 10; i++){
System.out.print(fibRec(i) + ", ");
}
}
privatestaticvoidprintFibonacciSeq(intcount){
inta = 0;
intb = 1;
intc = 1;
for(inti = 1; i<= count; i++){
System.out.print(a + ", ");
a = b;
b = c;
c = a + b;
}
}
privatestaticintfibRec(intcount){
if(count <= 1){
returncount;
}
returnfibRec(count -1) + fibRec(count - 2);
}
}