8000 Create math directory and recursive factorial · AllAlgorithms/java@104811b · GitHub
[go: up one dir, main page]

Skip to content

Commit 104811b

Browse files
joaodos3vabranhe
authored andcommitted
Create math directory and recursive factorial
1 parent 1324f1c commit 104811b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

math/RecursiveFactorial.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testes;
2+
/**
3+
* Java implementation of recursive factorial
4+
* @author @joao-vieira
5+
*/
6+
7+
public class RecursiveFactorial {
8+
9+
public int recursiveFactorial(int n) {
10+
if(n <= 1) return 1;
11+
return n * recursiveFactorial(n-1);
12+
}
13+
14+
public static void main(String[] args) {
15+
// Test
16+
int number = 3;
17+
System.out.println(number + "! = " + new RecursiveFactorial().recursiveFactorial(number));
18+
}
19+
20+
}

0 commit comments

Comments
 (0)
0