Skip to content

Commit b8f451b

Browse files
committed
Added recursive factorial in java
1 parent c7e5359 commit b8f451b

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

recursion/factorial.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
3+
public class factorial{
4+
5+
public static int fact(int i) {
6+
7+
if(i==1||i==0){
8+
9+
return 1;
10+
11+
}
12+
13+
else{
14+
15+
return i * fact(i-1);
16+
17+
18+
}
19+
20+
}
21+
22+
23+
public static void main (String [] args) {
24+
25+
Scanner sc = new Scanner(System.in);
26+
27+
int a = sc.nextInt();
28+
29+
30+
System.out.println(fact(a));
31+
32+
33+
}
34+
35+
}

0 commit comments

Comments
 (0)