public class Facts {

  // code for exercise 10

  public static void main(String[] args) {
    System.out.print("Type in your number -> ");
    int n = IOUtil.readInt();
    System.out.println("The " + n + "th factorial number is " + fact(n));
    System.out.println("The " + n + "th factorial number is " + fact1(n));
    System.out.println("The " + n + "th factorial number is " + fact2(n));
  }

  public static int fact(int n) {
    assert n >= 0 : "factorial: n must be >= 0"; // post: returns n!
    int result = 1;
    while (n != 0) {
      result *= n;
      n--;
    }
    return result;
  }

  public static int fact1(int n) {
    assert n >= 0 : "factorial: n must be >= 0"; // post: returns n!
    int result = 1;
    if (n == 0) {
      return 1;
    }
    do {
      result *= n;
      n--;
    } while (n != 0);
    return result;
  }

  public static int fact2(int n) {
    assert n >= 0 : "factorial: n must be >= 0"; // post: returns n!
    int result = 1;
    for (int i = 1; i <= n; i++) {
      result *= i;
    }
    return result;
  }

}
