用 java编程,急急急!!!

用 java编程,急急急!!!
利用java.math.BigInteger类(查看JDK_DOC),计算n!和2n,其中n由键盘输入。(n=100)
键盘输入代码:参考JavaInput.java

BigInteger的乘法示例

利用System.currentTimeMillis()可以计算出时间差,写一个同样的C++程序计算阶乘和乘方。各循环计算10000次,比较时间的异同。
import java.math.BigInteger;

public class BigInt {

public static void main(String[] args) {
Long t1 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
BigInteger n = new BigInteger("1");
int num = 100;
while (num >= 1) {
n = n.multiply(new BigInteger("" + num));
num--;
}
System.out.println(n);
}
Long t2 = System.currentTimeMillis();

System.out.println("耗时:"+(t2-t1));
}

}
long t1=System.currentTimeMillis();
BigInteger s=new BigInteger("1");
for( int i=1; i{
BigInteger b=new BigInteger("" + i);
s=s.multiply(b);
}
long t2=System.currentTimeMillis();
System.out.println(t2-t1);
← 上一篇: 下一篇: →