1 Star 0 Fork 0

伍磊/Java

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
FactorialRecursion.java 657 Bytes
Copy Edit Raw Blame History
shellhub authored 2019-10-29 12:40 +08:00 . FibonacciNumber
package Maths;
public class FactorialRecursion {
/* Driver Code */
public static void main(String[] args) {
assert factorial(0) == 1;
assert factorial(1) == 1;
assert factorial(2) == 2;
assert factorial(3) == 6;
assert factorial(5) == 120;
}
/**
* Recursive FactorialRecursion Method
*
* @param n The number to factorial
* @return The factorial of the number
*/
public static long factorial(int n) {
if (n < 0) {
throw new IllegalArgumentException("number is negative");
}
return n == 0 || n == 1 ? 1 : n * factorial(n - 1);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tae_yang/Java.git
git@gitee.com:tae_yang/Java.git
tae_yang
Java
Java
master

Search