/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/thealgorithms/maths/Factorial.java
23 строки
530 B
Piotr Idzik
Make `Factorial` a proper utility class (#4267)
29 июл 2023, 08:15
Не верифицирован
29 июл 2023, 08:15
087d523
Код
Авторство
О чём код?
package com.thealgorithms.maths; public final class Factorial { private Factorial() { } /** * Calculate factorial N using iteration * * @param n the number * @return the factorial of {@code n} */ public static long factorial(int n) { if (n < 0) { throw new IllegalArgumentException("Input number cannot be negative"); } long factorial = 1; for (int i = 1; i <= n; ++i) { factorial *= i; } return factorial; } }