Wednesday, October 12, 2011

CHALLENGE:Java Tut 35-Var Length Arguments

The following is a challenge for new developers that have completed:
 Java Tutorial - 35 Variable Length Arguments by theNewBoston
 To get the most out of these challenges try them a few hours or the day after watching/following along with the actual video.
 


B.A.M.F Challenge:
B.A.M.F Challenges & why you want to always at leas try them explained Here:http://bit.ly/ogivqe
Difficulty: 1/3
Create a console program with a method that finds the average of a unknown amount of numbers(aka accepts a variable length argument in its parameters)Then test it in you're main method.

CHALLENGE!!
(Before starting any of the challenges always declare a class and a main method unless told otherwise)
 Difficulty:
 
1.Create a method that will return a int and name it "average".It should accept a variable length argument, name the variable length argument "numbers"

Inside the "average" method:

2.Declare a int variable, name it total and set it to 0.

3.Create a enhanced for loop that loops through the "numbers" parameter being passed in.

Inside the enhanced for loop:
4.set total+=x;

5.return total divided by the amount of numbers you passed in(hint: numbers.length)

Back in the main method:


6.Create a print line statement that calls the "average" method and place 8 values in its parameters.


COMPILE & PRAY TO DUKE!!!


View the video tutorial: http://bit.ly/qkxfja 

No comments:

Post a Comment

 
;