|
-- Posted by Majo at 2:04 pm on Sep. 16, 2008
Here is what I have so far: | Code: | public class DataTypes { public void changeTypes() { int intVar = 89; int doubleVar = intVar; System.out.print((double)doubleVar); } } | Next, I'm to add another method called calcAvg but I'm not sure where I'm supposed to put it, what's proper. I don't recall doing this before and I didn't bring my 15 pound book with me ( ).
-- Posted by h a t t at 2:11 pm on Sep. 16, 2008
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 |
-- Posted by Majo at 2:21 pm on Sep. 16, 2008
Wow, whoa, I think that's...too advanced... I'm still in Programming for Info Tech I. I think I have it now though, thanks anyways for trying. 
|