/*****************************************************************
** Factorial - program to demonstrate non-recursive technique
** for computing the factorial of an integer
**
** A sample dialogue follows:
**
**    PROMPT>java Factorial
**    Enter an non-negative integer: 6
**    6! = 720
**
** (c) Scott MacKenzie, 2000                             
******************************************************************/
import java.io.*;

public class Factorial
{
   public static void main(String[] args) throws IOException
   {
      BufferedReader stdin =
         new BufferedReader(new InputStreamReader(System.in), 1);

      System.out.print("Enter a non-negative integer: ");
      int n = Integer.parseInt(stdin.readLine());
      if (n < 0)
      {
         System.out.println("Oops!");
         return;
      }
      else   
      System.out.println(n + "! = " + factorial(n));
   }

   public static int factorial(int n)
   {
      if (n == 0)
         return 1;
      for (int i = n - 1; i > 0; i--)
         n *= i;
      return n;
   }
}

