Skip to content

Commit bc7a3fc

Browse files
authored
Add Leonardo Number (TheAlgorithms#2649) (TheAlgorithms#2650)
1 parent 3bec562 commit bc7a3fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Maths/LeonardoNumber.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Maths;
2+
3+
public class LeonardoNumber {
4+
public static int leonardoNumber(int n) {
5+
if (n < 0) {
6+
return 0;
7+
}
8+
if (n == 0 || n == 1) {
9+
return 1;
10+
}
11+
return (leonardoNumber(n - 1) + leonardoNumber(n - 2) + 1);
12+
}
13+
14+
public static void main(String args[]) {
15+
for (int i = 0; i < 20; i++) {
16+
System.out.print(leonardoNumber(i) + " ");
17+
}
18+
19+
}
20+
}

0 commit comments

Comments
 (0)