We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 393ae33 commit ce14126Copy full SHA for ce14126
snippets/java/math/factorial.md
@@ -0,0 +1,22 @@
1
+---
2
+title: Factorial
3
+description: Computes the factorial of a given number
4
+author: Mcbencrafter
5
+tags: math,number,factorial
6
7
+
8
+```java
9
+public static BigInteger factorial(int number) {
10
+ BigInteger result = BigInteger.ONE;
11
12
+ for (int currentNumber = 1; currentNumber <= number; currentNumber++) {
13
+ result = result.multiply(BigInteger.valueOf(currentNumber));
14
+ }
15
16
+ return result;
17
+}
18
19
+// Usage:
20
+int number = 6;
21
+System.out.println(factorial(number)); // 720 = 6*5*4*3*2
22
+```
0 commit comments