package com.ethjava; //递归的第一个例子 //n!=n*n-1*n-2*...*1; public class jiecheng { public static void main(String[] args) { getJieChrng(5); } public static int getJieChrng(int n) { if (n == 0 || n == 1) { return 1; } else { //此时进行递归 int sum = n * getJieChrng(n - 1); System.out.println(sum); return sum; } } //2 //6 //24 //120 }
(递归上机)阶乘的案例
最新推荐文章于 2022-05-31 22:13:25 发布