import java.util.Scanner;
public class 求阶乘一句话 {
// 用一句话计算阶乘,用递归的思路解决
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请输入一个数");
int n = scanner.nextInt();
System.out.println(m(n));
}
}
private static int m(int n) {
// TODO Auto-generated method stub
return n == 1 ? 1 : n * m(n - 1);
}
}
java用一句话计算阶乘递归思路
最新推荐文章于 2022-09-13 11:19:42 发布