递归初探
public class TestDataStructure {
public static void main(String[] args) {
int n = 4;
int total = factorial(n);
System.out.println(total);//24
}
//阶乘递归算法
public static int factorial(int n){
if(n<=1){
return 1;
}else{
int subSolution = factorial(n-1);
int solution = subSolution*n;
return solution;
}
}
}