兄弟们看好了
楼主说的是 100
long 最多算到 20
想到 100 而且不失精度必须用 BigInteger
import java.math.BigInteger;
public class BigFactorial {
public static BigInteger calc(BigInteger src) {
BigInteger one;
BigInteger two;
BigInteger result;
one = new BigInteger("1");
two = new BigInteger("2");
result = new BigInteger(src.toString());
while (src.compareTo(two) > 0) {
result = result.multiply(src = src.subtract(one));
}
return result;
}
public static void main(String[] args) {
System.out.println(calc(new BigInteger("100")));
}
}
import java.math.*;
class f
{
public static void main(String[] args) {
BigInteger big = new BigInteger("1");
for (int i = 1 ; i<= 100; i++){
big = big.multiply(new BigInteger(String.valueOf(i)));
}
System.out.println(big);
public static void main(String[] args) {
BigInteger big = new BigInteger("1");
for (int i = 1 ; i<= 100; i++){
big = big.multiply(new BigInteger(String.valueOf(i)));
System.out.println(big);
}
}