站内搜索: 请输入搜索关键词

当前页面: 开发资料首页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名字让人糊涂啊,老大





↑返回目录
前一篇: 请各位前辈帮菜鸟解决下关于graphics.drawline的错误。
后一篇: 请教用什么命令:能去掉UNIX下某个目录(及其子目录)下所有*.htm文件内容中的“abcd”字符串