递归

递归

 

 


 

package base.method;

public class Demo05 {
  //递归思想
  public static void main(String[] args) {
      System.out.println(f(5));
  }
  //1!   1
  //2!   2*1
  //3!   3*2*1
  //4!   4*3*2*1
  //5!   5*4*3*2*1


  //2 2*f(1)
  //3   3*f(2)
  public static int f(int n){
      if (n==1){
          return 1;
      }else {
          return n*f(n-1);
      }
  }
}
posted @ 2022-05-14 16:48  怎样的人生  阅读(6)  评论(0)    收藏  举报