this is assuming that you're passing in an array of doubles. you put it above the public void changeTypes() method.
| Code: |
public static double calcAvg(double[] nums) { double hold = 0; for ( int i = 0; i < nums.length; ++i ) hold += nums; hold = hold / nums.length; return hold; } |
then to call it youd just do
| Code: |
double[] nums = {1,2,3,4,5}; //creat teh array double avg = calcAvg(nums); //call the function and let avg equal what's returned from it |
Post edited at 2:14 pm on Sep. 16, 2008 by h a t t