0

Please Who knows how to Write a program in java to call a method for calculating the factorial of any number

22nd Jan 2019, 2:29 PM
Oden David
Oden David - avatar
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));
22nd Jan 2019, 3:04 PM
Denise Roßberg
Denise Roßberg - avatar
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...
22nd Jan 2019, 2:53 PM
PapaBT
PapaBT - avatar