import java.math.BigInteger;

public class Big {

  public static void main (String[] args) {
    // print the factorial of the numbers from 0 to 30
    for (int i=0; i<30; i++) {
      System.out.println (i + "\t" + factorial (i));
    }
  }

  public static BigInteger convertToBig (int n) {
    String s = Integer.toString (n);
    BigInteger big = new BigInteger (s);
    return big;
  }

  // in factorial, I didn't need to make n or i BigIntegers,
  // since they only go up to 30

  public static BigInteger factorial (int n) {
    if (n==0) return convertToBig (1);

    BigInteger total = convertToBig (1);

    for (int i=1; i<=n; i++) {

      // but each time through the loop I have to convert the
      // current value of i to a BigInteger

      total = total.multiply (convertToBig(i));
    }
    return total;
  }
}
