递归调用指在方法执行的过程中,出现该方法本身的调用
1.找到递归的出口
2.找到递归关系式
例子1:
public class jiecheng{
public static void main(String args[]) {
System.out.println(method(5));
}
public static int method(int x) {
if(x == 1)
return 1;
else
return x*method(x - 1);
}
}
例子2:
public class HelloWorld{
public static void main(String args[]) {
System.out.println(method(5));
}
public static int method(int x) {
if(x == 1 || x == 2)
return 1;
else
return method(x - 1) + method(x - 2);
}
}