mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 21:43:15 +08:00
20
Maths/LeonardoNumber.java
Normal file
20
Maths/LeonardoNumber.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package Maths;
|
||||||
|
|
||||||
|
public class LeonardoNumber {
|
||||||
|
public static int leonardoNumber(int n) {
|
||||||
|
if (n < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (n == 0 || n == 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return (leonardoNumber(n - 1) + leonardoNumber(n - 2) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
System.out.print(leonardoNumber(i) + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user