// Program Name                  MathUtils.java
// Course:                       CSE 1302J
// Student Name:                 Bradley Shedd
// Assignment Number:            Lab#7
// Due Date:                     10/20/2010
// Purpose:                      This program provides static
//                               mathematical utility functions.

public class MathUtils
{
   
//-------------------------------------------------------------
    // Returns the factorial of the argument given
    //-------------------------------------------------------------
    public static int factorial(int n) throws IllegalArgumentException
    {
  
if (n<0)
     
throw new IllegalArgumentException("Please don't type negative numbers!");
     
if (n>16)
     
throw new IllegalArgumentException("The number is too large!" +
                                        
" Type a value less than 17.");
  
int fac = 1;
  
for (int i=n; i>0; i--)
      fac *= i;
  
return fac;
    }
   
//   System.out.println("Coded By: Bradley Shedd");
}

Homepage