how to find factorial number in java code example
Example 1: how to make factorial in java
class fact{
static int fac(int n){
int ans =1;
for(int i=1; i<=n; i++){
ans = ans*i;
}
return ans;
}
public static void main (String[] args){
int f = 5;
System.out.println(fac(f));
}
}
Example 2: factorial number in java
int num1 = 6;
int num2 = 1;
for(int a = 1; a<=num1; a++) {
num2 = num2 * a;
}
System.out.println(num2);