/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/thealgorithms/maths/LeonardoNumber.java
25 строк
640 B
Piotr Idzik
style: enable `HideUtilityClassConstructor` in checkstyle (#5147)
08 май 2024, 09:58
Не верифицирован
08 май 2024, 09:58
d3bb691
Код
Авторство
О чём код?
package com.thealgorithms.maths; /** * https://en.wikipedia.org/wiki/Leonardo_number */ public final class LeonardoNumber { private LeonardoNumber() { } /** * Calculate nth Leonardo Number (1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, ...) * * @param n the index of Leonardo Number to calculate * @return nth number of Leonardo sequences */ public static int leonardoNumber(int n) { if (n < 0) { throw new ArithmeticException(); } if (n == 0 || n == 1) { return 1; } return (leonardoNumber(n - 1) + leonardoNumber(n - 2) + 1); } }