JAVA编程------------22、利用递归求5!

 1 package FushiExam;
 2 import java.util.*;
 3 public class Text_22 {
 4 
 5     public static void main(String[] args) {
 6         // 利用递归方法求n!
 7         Scanner scan=new Scanner(System.in);
 8         int n=scan.nextInt();
 9         int sum=Fin(n);
10     System.out.println(n+"!="+sum);
11 
12     }
13     public static int Fin(int a) {
14         if(a==1)
15             return 1;
16         else
17             return a*Fin(a-1);
18     }
19 
20 }

 

posted @ 2020-03-14 13:08  Hey蜗牛  阅读(427)  评论(0)    收藏  举报