Add Leonardo Number (#2649) (#2650)

This commit is contained in:
Florian 2021-10-22 07:50:59 +02:00 committed by GitHub
parent 3bec562a1d
commit bc7a3fc3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

20
Maths/LeonardoNumber.java Normal file
View 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) + " ");
}
}
}