方法一: n!=1×2×3×……×n方法
package other;
import java.math.BigDecimal;
public class JieChen {
/**
* 1!+3!+5!+...+99!的阶乘为
* n!=1×2×3×……×n方法
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 1;
double count = 0, t = 1; //值太大,用double的科学计算法表示
while (num<100) {
for (int i = 1; i <= num; i++) {
t*=i; //n!=1×2×3×……×n
}
System.out.println(num+" 的阶乘为:" + t);
count += t;
t = 1;
num += 2;
}
System.out.println("1!+3!+5!+...+99!的阶乘为:" + count);
System.out.println(new BigDecimal(count)); //完整的将科学计算法的数字显示出来
}
}
方法二:n×(n-1)!方法
package other;
import java.math.BigDecimal;
public class JieChen4 {
/**
* 1!+3!+5!+...+99!的阶乘为
* n×(n-1)!方法
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 1;
double count = 1, t=1; //值太大,用double的科学计算法表示
while (num<100) {
if (num>1) {
t*=(num-1)*num; //n×(n-1)!
}
System.out.println(num+" 的阶乘为:" + t);
count += t;
num += 2;
}
System.out.println("1!+3!+5!+...+99!的阶乘为:" + count);
System.out.println(new BigDecimal(count)); //完整的将科学计算法的数字显示出来
}
}