Showing posts with label for loop. Show all posts
Showing posts with label for loop. Show all posts
Wednesday, October 12, 2011 0 comments

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 

Tuesday, October 11, 2011 0 comments

CHALLENGE:Java Tut 32-34-Arrays in Methods & Multidimensional Arrays

The following is a challenge for new developers that have completed:
 Java Tutorial's 32-34 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/2
 Create a java console program with a method that accepts a multidimensional array in its parameters.When the method is called it should print the array out to the console as a table.If you've done everything right you're results should look like this:


This is the the Multi Array
8        9        5          12
55      12        32         22
15       4        39         83




CHALLENGE!!
(Before starting any of the challenges always declare a class and a main method unless told otherwise)
 Difficulty:★2/3
1.Create a multidimensional array. It should have at least 3 arrays inside of it and each array should have several values.

2.Create a method that accepts a multidimensional array in its parameters, name the array in the parameters "x" and name the method "display"[

3.Inside the display method create a for loop, name you're counter "row; loop  through until x.length is less than "row" ; increment by 1

Inside of the "row" for loop insert: [

  • Another for loop. name you're counter "column"; loop  through until x.length is less than "x[row].length;increment by 1. Inside the "column" for loop insert:


  •    1.A print line statement that prints  x[row][column] + "\t"]

  • Print line statement that prints: a blank line] ]


    • 4.In the main method write a print line statement that reads "This is the array table"

      5.In the main method call the display method and place you're array in the parameters

      Note: I am trying to experiment to find the best way to explain loops in words. Everything that is Orange is inside of the "Row" for loop and everything that is red is inside the "column" for loop. If this made it easier for you to understand or you have some suggestions to improve these challenges leave it in a comment below!!


      COMPILE & PRAY TO DUKE!!!
      View the video tutorial: http://bit.ly/r9jFZN
      Monday, October 10, 2011 1 comments

      CHALLENGE:Java Tut 30-Array Elements As Counters

      The following is a challenge for new developers that have completed:
       Java Tutorial - 30 Array Elements As Counters by theNewBoston
       


      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/2
       Create a java console program using arrays and for loops that simulates a 6 sided die being tossed 1000 times. Then print the amount of times it fell on each side of the die to the console. Your console output should look something like this: 
      Face      Frequency
      1                182          
      2                 220         
      3                134          
      4                278          
      5                169         
      6                188          



      CHALLENGE!!
      (Before starting any of the challenges always declare a class and a main method unless told otherwise)
       Difficulty:★1/2
      1.Create a Random variable and name it rand
      2.Create a int array that holds 7 int's, name it freq. 
      3.Create a for loop that loops 1000 times.Each time it loops it should:
             *++freq[1+rand.nextInt(6)];
      4.Below the for loop print a header that reads "Face        Frequency"
      5.Create another for loop:
        Start you're "counter" at 1, the loop should continue as long as face is less than the length of the freq array , increment by 1 , each time it loops it should :
                         *Print the index , a few spaces and the value of the index position.(See the example in the                      B.A.M.F example if you're confused.

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

       
      ;