方法:递归讲解
方法:递归讲解
package com.andy.base.Andy.operator.method;
public class Demo05 {
public static void main(String[] args) {
//递归头:什么时候不调用自身方法,如果没有头,将陷入死循环
//递归体:什么时候需要调用自身方法
Demo05 test = new Demo05();
test.test();
//这就报错了
}
public void test(){
test();
}
}
package com.andy.base.Andy.operator.method;
public class Demo06 {
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);
}
}
}
浙公网安备 33010602011771号