public class Demo05 {public static void main(String[] args) {System.out.println(f(5));}// 5! 5*4*3*2*1 阶乘public static int f(int n){if (n==1){return 1;} else {return n*f(n-1);}} } 递归特别消耗资源,如果嵌套太多层就不建议使用了 https://www.bilibili.com/video/BV12J41137hu?p=50&spm_id_from=pageDriver