一、递归概述
示例:
package com.itbianma12; public class Demo { public static void main(String[] args){ System.out.println(f(20)); } public static int f(int n){ if (n==1||n==2){ return 1; }else{ return f(n-1)+f(n-2); } } }
二、案例
1、递归求阶乘
package com.itbianma12; public class Demo { public static void main(String[] args){ System.out.println(jc(3)); } public static int jc(int n){ if(n==1){ return 1; }else{ return n*jc(n-1); } } }
2、遍历目录
示例:
标签:return,递归,int,static,java,public,jc From: https://www.cnblogs.com/qtiger/p/17900818.html