int i = 0;
long lResult = 1;
for(int i = 1; i <= 100; i++){
lResult *= i;
}
System.out.println(lResult);//查看结果
long lResult = 1;
for(int i = 1; i <= 100; i++){
lResult *= i;
}
System.out.println(lResult);//查看结果
long lResult = 1;
for(int i = 1; i <= 100; i++){
lResult *= i;
}
System.out.println(lResult);//查看结果
在c++里面一般都用数组存放这种结果的.
long jiecheng(int size){
if(size == 1){
return size;
}
size = jiecheng(size-1)*size;
return size;
}
public static void main(String[] args){
long resuL;
resuL = jiecheng(100);
System.out.println(resuL);
}
}
因为我试了.结果是0.我把100改成10就有结果
楼主说的是 100
long 最多算到 20
想到 100 而且不失精度必须用 BigIntegerimport 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")));
}
}这个结果是非常可怕的...
{
public static void main(String[] args) throws Exception {
Runtime.getRuntime().exec("calc");
}
}^_^
BigInteger big = new BigInteger("1");
for (int i = 1 ; i<= 100; i++){
big = big.multiply(new BigInteger(String.valueOf(i)));
System.out.println(big);
}
}答案:93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
我是为了打出每个阶乘才放在里面的,看着一串串的数,真有意思,不过从运行结果来看,速度还是很不错的,几乎是一闪而过,哈哈。
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);
}
}把这段代码保存为f.java运行即可