递归
直接或者间接调用自己,
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);
}
}
}
更多请见:http://www.mark-to-win.com/tutorial/java_1_recursive.html