// Iterative factorial method.
public class FactorialCalculator
{
// recursive declaration of method factorial
public long factorial( long number )
{
long result = 1;
// iterative declaration of method factorial
for ( long i = number; i >= 1; i-- )
result *= i;
return result;
} // end method factorial
// output factorials for values 0-10
public void displayFactorials()
{
// calculate the factorials of 0 through 10
for ( int counter = 0; counter <= 10; counter++ )
System.out.printf( "%d! = %d\n", counter, factorial( counter ) );
} // end method displayFactorials
} // end class FactorialCalculator
(Using the FactorialCalculator): Modify the program to allow input on what factorial is required instead of 10.
Under discussion
Comments
- Popular
- New
- Old
You must be signed in to leave a comment
This page doesn't have any comments yet