Skip to content

Commit 02f48ce

Browse files
Added Java Program to find Factorial
1 parent 56f1568 commit 02f48ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Factorial.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.*;
2+
public class Factorial
3+
{
4+
public static int fact(int n)
5+
{
6+
int fact=1;
7+
for(int i=n;i>=1;i--)
8+
{
9+
fact=fact*i;
10+
}
11+
return fact;
12+
}
13+
14+
public static void main(String arg[])
15+
{
16+
Scanner in = new Scanner(System.in);
17+
System.out.println("Enter the number:");
18+
int n = in.nextInt();
19+
int f = fact(n);
20+
System.out.println("Factorial of "+n+" is "+f);
21+
}
22+
}

0 commit comments

Comments
 (0)