当前位置:网站首页>2021-04-16 recursion

2021-04-16 recursion

2022-06-23 10:07:00 Deer like deer

recursive

Recursion is to call yourself
The utilization structure consists of two parts :

  1. Recursive header : When not to call your own methods , If there is no head , Will fall into a dead cycle
  2. Recursive body : When do I need to call my own methods
public class Demo5 {
    
    public static void main(String[]args){
    
        System.out.println(f(5));
    }
    public static int f(int n){
    
        if(n==1){
    
            return 1;
        }
        else{
    
            return n*f(n-1);
        }
    }
}
原网站

版权声明
本文为[Deer like deer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230954196056.html