int i = 0;
long lResult = 1;
for(int i = 1; i <= 100; i++){
    lResult *= i;
}
System.out.println(lResult);//查看结果

解决方案 »

  1.   

    //int i = 0;    -------------------->不要
    long lResult = 1;
    for(int i = 1; i <= 100; i++){
        lResult *= i;
    }
    System.out.println(lResult);//查看结果
      

  2.   

    我想知道java里面的long能存多大的数啊?
    在c++里面一般都用数组存放这种结果的.
      

  3.   

    public class Resul{
    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);
    }
    }
      

  4.   

    楼上的好象有点问题.我运行了.提示俩错误.还有.100的阶乘结果是不是超出long的范围了。
    因为我试了.结果是0.我把100改成10就有结果
      

  5.   

    兄弟们看好了
    楼主说的是 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")));
        }
    }这个结果是非常可怕的...
      

  6.   

    public class Calc

    public static void main(String[] args) throws Exception { 
    Runtime.getRuntime().exec("calc");

    }^_^
      

  7.   

    import java.math.*;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);
        }
    }答案:93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
      

  8.   

    上面的那个人写错了,System.out.println()应该写在for的外面
      

  9.   

    to: guangchao()
    我是为了打出每个阶乘才放在里面的,看着一串串的数,真有意思,不过从运行结果来看,速度还是很不错的,几乎是一闪而过,哈哈。
      

  10.   

    有谁知道BigInteger是如何来计算的吗?
      

  11.   


    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运行即可