public class Avg
{
  static double avgOld( double[] array )
  {
    double sum = 0;
    
    for ( int i = 0; i < array.length; i++ )
      sum += array[ i ];

    return sum / array.length;
  }

  static double avg( double[] array )
  {
    if ( array == null || array.length == 0 )
      throw new IllegalArgumentException( "Illegal array!" );
  
    double sum = 0;
  
    for ( double n : array )
      sum += n;
  
    return sum / array.length;
  }

  /**
   * @param args
   */
  public static void main( String[] args )
  {
    double avg = avg( new double[]{ 2, 3, 4} );
    System.out.println( avg );
  }
}
