一个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);
}