Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
Like Tree1Likes

Thread: Smallest numbers

  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,022
    Blog Entries
    7
    Rep Power
    20

    Default Re: Smallest numbers

    Quote Originally Posted by Fubarable View Post
    He's not a caveman, he's dutch... wooden shoes, wooden head, wouldn't listen...
    Tolls started this! I didn't do anything and Tolls waved his willy-nilly at me! honest!

    kindest regards,

    Jos (runs ---------------------------------------------------------------> that a'way)
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Smallest numbers

    Ugh...
    I'm confused again.
    I need to make a method which takes 1 parameter: Player[]
    I don't know how many players there is going to be in the array.
    How can I make it so it will loop through each of the players and return which one is the best?

    Note: I'm not very good at loops.

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Smallest numbers

    Let's start with this: if the method takes (Player[] players) as its parameter, how many times will the for loop loop? From i = 0 to i < what?

  4. #24
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Smallest numbers

    Quote Originally Posted by Fubarable View Post
    Let's start with this: if the method takes (Player[] players) as its parameter, how many times will the for loop loop? From i = 0 to i < what?
    players.length

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Smallest numbers

    Quote Originally Posted by PhQ View Post
    players.length
    Exactly, so in fact you do know how many Players will be in the array at the time the method is called. So set a Player bestPlayer variable to refer to the first Player in the array (checking to make sure that there is at least 1 Player in the array), loop through and compare each player against the current "best" Player (however you define this), and then after the loop ends, return the bestPlayer.

  6. #26
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 12
    Last Post: 09-08-2011, 05:03 PM
  2. Return smallest value
    By jaylimix in forum New To Java
    Replies: 8
    Last Post: 06-06-2011, 06:11 PM
  3. Replies: 11
    Last Post: 01-14-2011, 06:36 PM
  4. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-14-2008, 11:46 PM
  5. Getting smallest possible Double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •