java中递归的用法和例子
递归
直接或者间接调用自己,
public class Test{
public static void main(String[] args){
int i = 5;
System.out.println("5!=" + fac(5));
}
static long fac(long n){
/*fac(5)=5*4*3*2*fac(1)*/
if (n<=1){
return 1;
}else{
return n*fac(n-1);
}
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/101207784