java 求阶乘
package com.oop;
public class factorical {
public static void main(String[] args) {
long result = sumOf(10);
System.out.println(result);
long sum = sum(10);
System.out.println(sum);
}
public static long sumOf(int n) {
if (n == 1 || n == 0) {
return 1;
}
else {
return n*sumOf(n-1);
}
}
public static long sum(int n) {
long total = 1;
for(int i = 1; i <= n;i++) {
total *= i;
}
return total;
}
}
本文来自博客园,作者:wjxuriel,转载请注明原文链接:https://www.cnblogs.com/my-blog-site/p/16392071.html

浙公网安备 33010602011771号