LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 581 users online 225550 members 754 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
rocket boy
Peeves: Feminine boys, Jocks and really pretty...
Mood: Lonely
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
4 online / 32 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Adding another method to your functional class (Java).
Replies: 2Last Post Sep. 16, 2008 2:21pm by Majo
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Majo )


Soothsayer
Reply
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 ().

-------
"Under the hardness of her facade a woman's heart is still beating."


2:04 pm on Sep. 16, 2008 | Joined: May 2005 | Days Active: 301
Join to learn more about Majo Pennsylvania, United States | Straight Female | Posts: 6,733 | Points: 10,531
LiveWire Humor
h a t t



Patron
Reply
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


2:11 pm on Sep. 16, 2008 | Joined: June 2008 | Days Active: 305
Join to learn more about h a t t Ontario, Canada | Straight Male | Posts: 9,365 | Points: 31,968
( Majo )


Soothsayer
Reply
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.

-------
"Under the hardness of her facade a woman's heart is still beating."


2:21 pm on Sep. 16, 2008 | Joined: May 2005 | Days Active: 301
Join to learn more about Majo Pennsylvania, United States | Straight Female | Posts: 6,733 | Points: 10,531
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic