public class RecursiveFactorial
{
public static void main( String [] args )
{
// compute factorial of 7 and output it
System.out.println( "Factorial ( 7 ) is "
+ factorial( 7 ) );
}
public static int factorial( int n )
{
if ( n <= 0 ) // base case
return 1;
else // general case
return ( n * factorial ( n - 1 ) );
}
}
No comments:
Post a Comment