当前位置: 代码迷 >> J2SE >> 一个BigInteger的有关问题
  详细解决方案

一个BigInteger的有关问题

热度:59   发布时间:2016-04-24 00:58:04.0
一个BigInteger的问题
import java.math.BigInteger;

public class FactorialCalculatorBigInteger {

public static BigInteger factorial( BigInteger number )
{
BigInteger result = BigInteger.ONE;

for( BigInteger i = number; i.compareTo( BigInteger.ONE ) != -1; 
i.subtract( BigInteger.ONE ) )
{
result.multiply( i );
}

return result;
}

public static void main( String[] args )
{
for( int counter = 0; counter <= 3; counter++ )
{
System.out.printf( "%d! = %d\n", counter, factorial(BigInteger.valueOf(counter)) ) ;
}
}
}
这个哪里错了 怎么结果只是的
0!=1

------解决方案--------------------
Java code
for( BigInteger i = number; i.compareTo( BigInteger.ONE ) != -1;              [color=#FF0000]i = i.subtract( BigInteger.ONE )[/color] )
------解决方案--------------------
Java code
        for( BigInteger i = number; i.compareTo( BigInteger.ONE ) != -1;                 i = i.subtract(BigInteger.ONE)){            result = result.multiply(i);        }
  相关解决方案