Skip to content

Commit 5b0cc81

Browse files
committed
added snippet for calculating nth fibonacci number
1 parent ee95621 commit 5b0cc81

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

snippets/java/math/fibonacci.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Fibonacci
3+
description: Calculates the nth fibonacci number
4+
author: Mcbencrafter
5+
tags: math,number,fibonacci
6+
---
7+
8+
```java
9+
public static int fibonacci(int number) {
10+
if (number <= 1)
11+
return number;
12+
13+
return fibonacci(number - 1) + fibonacci(number - 2);
14+
}
15+
16+
// Usage:
17+
int number = 5;
18+
System.out.println(fibonacci(number)) // 3 (0, 1, 1, 2, 3)
19+
```

0 commit comments

Comments
 (0)