递归

public class Dome06 {
public static void main(String[] args) {
System.out.println(f(5));
}
//递归:自己调用自己就是递归,适合用于小数字运算,大数容易卡死电脑,看情况使用

public static int f(int n) {
if (n==1){
return 1;//递归头:什么时候不需要调用自己,如果没有头,将陷入死循环
}else{
return n*f(n-1);//递归体:什么时候需要调用自己
}
}
}
posted @ 2021-09-12 00:36  fantasyfa  阅读(34)  评论(0)    收藏  举报