CS 1713 Introduction to Computer Science, Spring 2008 Quiz 2 Comments

19 people took this quiz. Three people got 1 point and 3 people got 2 points.

  1. Write a method that takes and array of integers as a parameter and returns the average of the values stored in the array. If the array has no elements, return 0.
       public double getAverage(int[] array) {
          int sum = 0;
          if (array.length == 0)
             return 0.0;
          for (int i=0;i<array.length;i++)
             sum = sum + array[i];
          return sum/(double)array.length;
       }