import java.Math.BigInteger;
import java.util.*;
public class fac
{
protected static ArrayList table=new Arraylist();
static
{
table.add(BigInteger.valueOf(1));
}
public static synchronized BigInteger fac(int x)
{
if(x<0) throw new IllegalArgumentException("x must be non-negative");
for(int size=table.size();size<=x;size++)
{
BigInteger lastfact=(BigInteger)table.get(size-1);
BigInteger nextfact=lastfact.multiply(BigInteger.table.valueOf(size));
table.add(nextfact);
}
return (BigInteger)table.get(x);
}
public static void main(String[] para)
{
for(int i=0;i<=50;i++)
{
System.out.println(i+"!="+factorial(i));
}
}
}import java.Math.BigInteger;编译时说包不存在?为什么?难道还要建一个包?这不是java提供的吗?再一个系统为什么总是把math中的M大写?
import java.util.*;
public class fac
{
protected static ArrayList table=new Arraylist();
static
{
table.add(BigInteger.valueOf(1));
}
public static synchronized BigInteger fac(int x)
{
if(x<0) throw new IllegalArgumentException("x must be non-negative");
for(int size=table.size();size<=x;size++)
{
BigInteger lastfact=(BigInteger)table.get(size-1);
BigInteger nextfact=lastfact.multiply(BigInteger.table.valueOf(size));
table.add(nextfact);
}
return (BigInteger)table.get(x);
}
public static void main(String[] para)
{
for(int i=0;i<=50;i++)
{
System.out.println(i+"!="+factorial(i));
}
}
}import java.Math.BigInteger;编译时说包不存在?为什么?难道还要建一个包?这不是java提供的吗?再一个系统为什么总是把math中的M大写?
1。{
protected static ArrayList table=new Arraylist();
----------------------
Arraylist()应该是 ArrayList();
2.factorial(i)函数在哪啊?
3.楼上包的写法是正确的,大写Math类在java.lang包里
package test;import java.math.BigInteger;
import java.util.*;public class Fac {
protected static ArrayList table = new ArrayList();
static {
table.add(BigInteger.valueOf(1));
} public static synchronized BigInteger fac(int x) {
if (x < 0)
throw new IllegalArgumentException("x must be non-negative");
for (int size = table.size(); size <= x; size++) {
BigInteger lastfact = (BigInteger) table.get(size - 1);
BigInteger nextfact = lastfact.multiply(BigInteger.valueOf(size));
table.add(nextfact);
}
return (BigInteger) table.get(x);
} public static void main(String[] para) {
for (int i = 0; i <= 50; i++) {
System.out.println(i + "!=" + fac(i));
}
}
}
最后建议你用eclipse 开发,免得有很多错误!