QuestionAsk Questions?

The factorial method is used frequently in probability problems. The factorial of a positive integer n (written as n!) is equal... class Factorial Example{ public static long factorial(int n){ if(n <= 1

View Answers

April 10, 2008 at 7:32 PM

Hi friend

public class FactorialExample{

public static long factorial(int n){

if(n <= 1) // base case

return 1;

else

return n * factorial(n - 1);

}

public static void main(String [] args){

for(int i = 1; i <= 10; i++)

System.out.println(factorial(i));

}

}

--------------------------

Read for more information.

http://www.roseindia.net/java/beginners/Factorial.shtml

public class FactorialExample{

public static long factorial(int n){

if(n <= 1) // base case

return 1;

else

return n * factorial(n - 1);

}

public static void main(String [] args){

for(int i = 1; i <= 10; i++)

System.out.println(factorial(i));

}

}

--------------------------

Read for more information.

http://www.roseindia.net/java/beginners/Factorial.shtml

Related Tutorials/Questions & Answers:

Advertisements