// Exercise4_8.java: Compute factorial using iterations
public class Exercise4_8
{
  public static void main(String[] args)
  {
    // Prompt the user to enter an integer
    System.out.println("Please enter a nonnegative integer");
    int n = MyInput.readInt();

    System.out.println("Factorial of " + n + " is " + factorial(n));
  }

  // Iterative method for computing factorial of n
  static long factorial(int n)
  {
    long result = 1;

    for (int i=1; i<=n; i++)
      result *= i;

    return result;
  }
}
