12.4. Factorial Using Apache Commons Math
2Apache Commons Math has a CombinatoricsUtils class with a static factorial method that we can use to calculate the factorial.
3
4To include Apache Commons Math, we'll add the commons-math3 dependency into our pom:
5
6<dependency>
7 <groupId>org.apache.commons</groupId>
8 <artifactId>commons-math3</artifactId>
9 <version>3.6.1</version>
10</dependency>
11Let's see an example using the CombinatoricsUtils class:
12
13public long factorialUsingApacheCommons(int n) {
14 return CombinatoricsUtils.factorial(n);
15}