Results 1 to 7 of 7
  1. #1
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Smile need help, weird question kinda.

    basicly what i need is some code that takes the current time, and gets the seconds and divides it by 3 and rounds it so its a whole number between 1-20

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    What have you got so far? (please remember to use code tags)
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    well i know how to get the time.

    int sec = cal.get(Calendar.SECOND);

  4. #4
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Fair enough, so there's 60 seconds in a minute, right? You have a variable that represents the current seconds', take that value and divide it by three and use I believe Math.round() -> or something to that effect, I'm not sure of the exact use but there is one in the API. If you divide 60 by 3 that result has to be 20 or less by the operation rule you performed. For example, if (sec == 42) and (42 / 3) = 14 finally, 14 < 20.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  5. #5
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    int sec = cal.get(Calendar.SECOND);
    int sec2 = sec / 3;
    int sec3 = Math.round(sec2);
    ok now i need to put this through an equation that makes it psuedorandom because my assignment is to generate 10,000 numbers 1-20, i got the seed, now i need help with an equation to put it through to keep it 1-20, any suggestions?

  6. #6
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    eh, any suggestions? ^^

  7. #7
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    well you could use a while loop until the number is between 20.

    Java Code:
    boolean done = false;
    while(!done)
    {
         int sec = cal.get(Calendar.SECOND);
         int sec2 = sec / 3;
         int sec3 = Math.round(sec2);
         
         if(sec3 >= 1 && sec3 <= 20)
               done = true;
    
    }
    Now, it does the process until the final number is between 1 and 20.

    Does this help?

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 10:51 AM
  3. Weird data output
    By Shaolin in forum New To Java
    Replies: 12
    Last Post: 12-11-2007, 04:27 PM
  4. weird looking shape JButton is it possible?
    By unhurt in forum AWT / Swing
    Replies: 8
    Last Post: 11-03-2007, 09:10 AM
  5. k this is my ultimate project. kinda
    By jason27131 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 04:47 AM

Posting Permissions

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