递归

 

 

 

 

 1 package com.lin.method;
 2 //能不用递归就不用递归,可用其他方法代替
 3 //基数比较小的情况可以使用
 4 public class Demo5 {
 5     public static void main(String[] args) {
 6         //5! 5*4*3*2*1 阶乘
 7         //递归思想
 8         System.out.println(f(5));
 9     }
10     public static int f(int n){
11         if (n==1){
12             return 1;
13         }else {
14             return n*f(n-1);
15         }
16     }
17 }

 

posted @ 2021-02-14 14:53  奔啵儿灞  阅读(32)  评论(0)    收藏  举报