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

Printable View

- 01-14-2008, 04:15 AMcarlos123need 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

- 01-14-2008, 04:34 AMCaptainMorgan
What have you got so far? (please remember to use

*code*tags) - 01-14-2008, 04:38 AMcarlos123
well i know how to get the time.

Quote:

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

- 01-14-2008, 04:52 AMCaptainMorgan
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.

- 01-14-2008, 05:07 AMcarlos123Quote:

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

int sec2 = sec / 3;

int sec3 = Math.round(sec2);

- 01-17-2008, 11:45 PMcarlos123
eh, any suggestions? ^^

- 01-22-2008, 04:19 AMgibsonrocker800
well you could use a while loop until the number is between 20.

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;

}

Does this help?