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
热门推荐
3 送蛇的祝福语简短
6 足球队祝福语简短
10 送灯祝福语简短独特
11 诗词文案祝福语简短精辟
12 永远漂亮祝福语女生简短
13 祝福语简短古诗词
14 提早庆祝生日祝福语简短
15 女生 节日祝福语简短大气
16 初升高祝福语家长简短
17 幼儿祝福语押韵句子简短
18 航空公司祝福语简短