Skip to content

Commit 91dfe67

Browse files
committed
First Factorial
1 parent fb5aa21 commit 91dfe67

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/easy/FirstFactorial.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package easy;
2+
3+
/**
4+
* Have the function FirstFactorial(num) take
5+
* the num parameter being passed and return the factorial of it.
6+
* For example: if num = 4, then your program
7+
* should return (4 * 3 * 2 * 1) = 24.
8+
* For the test cases, the range will be between 1 and 18
9+
* and the input will always be an integer.
10+
*/
11+
public class FirstFactorial {
12+
13+
/**
14+
* First Factorial function.
15+
*
16+
* @param num input number
17+
* @return facorial of the given number
18+
*/
19+
private static int firstFactorial(int num) {
20+
if (num == 0) {
21+
return 1;
22+
} else {
23+
return num * firstFactorial(num - 1);
24+
}
25+
}
26+
27+
/**
28+
* Entry point.
29+
*
30+
* @param args command line arguments
31+
*/
32+
public static void main(String[] args) {
33+
var result1 = firstFactorial(4);
34+
System.out.println(result1);
35+
var result2 = firstFactorial(8);
36+
System.out.println(result2);
37+
}
38+
39+
}

0 commit comments

Comments
 (0)