Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b0cc81

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /