Write a java Program to read a number from command prompt to calculate the factorial using recursion |EasyCoding45
Write a java Program to read a number from command prompt to calculate the factorial using recursion.
In this tutorial, we are going to learn how we can Write a java Program to read a number from command prompt and calculate the factorial using recursion.
Program :-
import java.util.*;
class factorial
{
int fact(int num)
{
if(num>=1)
return num*fact(num-1);
else
return 1;
}
public static void main(String ap[])
{
int n=Integer.parseInt(ap[0]);
factorial f=new factorial();
int ans=f.fact(n);
System.out.println("Factorial of a number is :"+ans);
}
}
Output :-
Thank you💚
Ek no bro
ReplyDeleteThanks bruh😍
Delete