0
Please Who knows how to Write a program in java to call a method for calculating the factorial of any number
2 Réponses
+ 1
An example for small numbers:
int num = 5;
int factorial = 1;
for(int i = num; i > 0; i--){
factorial*=i;
}
System.out.println(factorial);
public static int factorial (int num){
//calculate factorial
return factorial;
}
main:
System.out.println (factorial (num));
0
In the challange https://www.sololearn.com/learn/6639/?ref=app
are some solutions. But the fractional grows very fast, so you have the problem to choose the datatype. Biginteger could be the right choice .
Good luck...