-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursion
More file actions
40 lines (33 loc) · 770 Bytes
/
Copy pathRecursion
File metadata and controls
40 lines (33 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* This program will display the factorial for a number
* CS 49
* Hanzhuo Gong
*/
public class TestFactorial {
public static void main(String[] args) {
System.out.println("8!= " + UserfulRoutines.factorial(8));
System.out.println("11!= " + UserfulRoutines.factorial(11));
System.out.println("0!= " + UserfulRoutines.factorial(0));
System.out.println("7!= " + UserfulRoutines.factorial(7));
}
}
/**
* Method for calculate the factorial number
* CS 49
* Hanzhuo Gong
*/
public class UserfulRoutines {
public static long factorial(int num) {
if (num < 0)
return 0;
if (num == 0)
return 1;
return factorial(num-1)*num;
}
}
/*------------------------------output---------------------------
8!= 40320
11!= 39916800
0!= 1
7!= 5040
*/