public class Factorielle {

  long[] table;			// Créer une table pour stocker les valeurs
  int last;			// Dernière factorielle calculée

  public Factorielle() {
    table = new long[21];
    table[0] = 1;
    last = 0;
  }

  public long calculFactorielle(int x) {
    if(x>=table.length) {
      System.out.println("x est trop grand");
      return table[0];
    }
    else {
      while(last < x) {
        table[last+1]=table[last]*(last+1);
        last++;
      }
      return table[x];
    }
  }

  public static void main (String args[]) {
    if (args.length < 1) {
      System.out.println("Usage: java Factorielle <number> ");
      System.exit(1);
    }
    else {
      Factorielle f=new Factorielle();
      int maxInt = Integer.parseInt(args[0]);
      for (int i=1; i<=maxInt; i++) {
        System.out.println(i + "! = " + f.calculFactorielle(i));
      }
    }
  }
}