import java.util.*;
public class FactMethod
{
void fact(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("\n Factorial of "+n+" is = "+fact);
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("\n Enter Number...");
int number = s.nextInt();
FactMethod obj = new FactMethod();
obj.fact(number);
}
}
Output:
Enter Number...
5
Factorial of 5 is = 120
Basic Java programs. All programs done in very simple ways. It helps beginners to grow their programming skills and build a programming logic.
Monday, 7 December 2020
Factorial of Number using Method
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment
If you have any doubts, please let me know