当前页面: 开发资料首页 → J2SE 专题 → 1!+2!+...+100!
1!+2!+...+100!
摘要: 1!+2!+...+100!
如题。
1,比较简单的算法。
2,效率高的算法。
sf
import java.math.* ;
public class Test
{
BigInteger sum = new BigInteger("0") ;
BigInteger tmp = new BigInteger("1") ;
public static void main( String args[] )
{
Test t = new Test() ;
for ( int i = 1; i<=100; i++ )
{
BigInteger ii = new BigInteger( new Integer(i).toString() ) ;
t.add( ii ) ;
}
System.out.println (t.sum.toString()) ;
}
public void add( BigInteger bi )
{
tmp = tmp.multiply( bi ) ;
sum = sum.add( tmp ) ;
}
}
不知道是不是和你的要求
不对吧???
晕,add名字让人糊涂啊,老大
牛