编写一段程序,用于计算200以内正整数的阶乘
要求: 不允许使用任何第三方库。
import java.util.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(solution(n));
}
public static BigInteger solution(int n) {
BigInteger x = BigInteger.valueOf(1);
BigInteger y = BigInteger.valueOf(2);
BigInteger z = BigInteger.ZERO;
for(int i = 1; i < n ; i ++) {
z = x.multiply(y);
x = z;
y = y.add(BigInteger.valueOf(1));
}
return x;
}
}
提供一种新思路