factorial number in java
int num1 = 6;
int num2 = 1;
for(int a = 1; a<=num1; a++) {
num2 = num2 * a;
}
System.out.println(num2);
factorial number in java
int num1 = 6;
int num2 = 1;
for(int a = 1; a<=num1; a++) {
num2 = num2 * a;
}
System.out.println(num2);
factorial method library in java
2.4. Factorial Using Apache Commons Math
Apache Commons Math has a CombinatoricsUtils class with a static factorial method that we can use to calculate the factorial.
To include Apache Commons Math, we'll add the commons-math3 dependency into our pom:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
Let's see an example using the CombinatoricsUtils class:
public long factorialUsingApacheCommons(int n) {
return CombinatoricsUtils.factorial(n);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us