LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 661 users online 225148 members 1019 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
biitwixed
Movies: twilight, wedding crasher, john tucker...
Mood: Flirty
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
9 online / 18 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Quoting Post
Archived Topic: It will not be bumped to the top of the forum.
Topic Adding another method to your functional class (Java).
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
Majo Posted 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 ().

Replies
Majo Posted 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.

h a t t Posted 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

All 2 previous replies displayed.