Skip to content

Commit 4bb9f32

Browse files
committed
Rucursion: Factorial
1 parent f12261b commit 4bb9f32

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
*
3+
*/
4+
package com.sanket.recursion;
5+
6+
/**
7+
* @author Sanket Gupta
8+
*
9+
*/
10+
public class Factorial {
11+
12+
/**
13+
* @param args
14+
*/
15+
public static void main(String[] args) {
16+
17+
int i = 10; //Integer.parseInt(args[0]);
18+
int output = factorial(i);
19+
System.out.println(i+"! = "+output);
20+
21+
}
22+
23+
/**
24+
*
25+
* @param i
26+
* @return
27+
*/
28+
public static int factorial(int i) {
29+
if(i>1)//break condition
30+
return i * factorial(i -1);//recursion
31+
else
32+
return 1;
33+
}
34+
35+
}

0 commit comments

Comments
 (0)