File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments