1.

Write A Program To Find The Factorial Of A Number ?

Answer»

Following is a program for factorial of a NUMBER using Recursion in Java.

1. public class Factoria{

2. 3. static int DISPLAY(int n){

4. if (n == 0)

5. return 1;

6. else

7. return(n * display(n-1));

8. }

9. public static VOID main(String args[]){

10. int i, fact=1;

11. int number=5;//It is the number to calculate factorial

12. fact = display(number);

13. System.out.println("Factorial of "+number+" is: "+fact);

14. }

15. }

Output:

Factorial of 5 is: 120

Following is a program for factorial of a number using Recursion in Java.

1. public class Factoria{

2. 3. static int display(int n){

4. if (n == 0)

5. return 1;

6. else

7. return(n * display(n-1));

8. }

9. public static void main(String args[]){

10. int i, fact=1;

11. int number=5;//It is the number to calculate factorial

12. fact = display(number);

13. System.out.println("Factorial of "+number+" is: "+fact);

14. }

15. }

Output:

Factorial of 5 is: 120



Discussion

No Comment Found