Java中的阶乘除数
以下是一个Java程序,用于查找数字的阶乘除数。
程序
import java.util.Scanner;
public class DivisorsOfFactorial {
public static long fact(int i) {
if(i <= 1) {
return 1;
}
return i * fact(i - 1);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("输入n值:");
int n = sc.nextInt();
int result = 0;
long fact = fact(n);
for (int i = 1; i<= fact; i++) {
if (fact%i == 0) {
result = result+i;
}
}
System.out.println(result);
}
}输出结果
输入n值: 4 60
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语