Skip to content

Commit 37f35ff

Browse files
Recursion method to find factorial
1 parent 9382652 commit 37f35ff

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

factorial.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import java.util.*;
2-
public class factorial{
2+
public class factorial
3+
{
4+
public static int fact(int i)
5+
{
6+
if(i==1)
7+
return 1;
8+
else
9+
return i*fact(i-1);
10+
}
311

412
public static void main(String args[])
513
{
6-
Scanner s=new Scanner(System.in);
7-
int n=s.nextInt();
8-
long f=1;
9-
10-
for(int i=1;i<=n;i++)
11-
f=f*i;
12-
System.out.println(f);
13-
14+
Scanner s=new Scanner(System.in);
15+
int n=s.nextInt();
16+
System.out.println(fact(n));
1417
}
15-
1618
}

0 commit comments

Comments
 (0)