Author |
Message |
abogaida
|
Posted: Wed Apr 08, 2009 3:02 pm Post subject: Program help? |
|
|
I am new in java. I just finished my first course in it. I was thinking of making this program about a little game that when I was young my parents used to play with us. The game is about math mathematics. Not to bore you with the details, I was wondering how can make a program to select a random integer number. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jbking
|
|
|
|
 |
matt271

|
Posted: Wed Apr 08, 2009 3:45 pm Post subject: Re: Program help? |
|
|
this will give u a random number between 0 and 1 (non-include)
Java: | double x = Math.random(); |
if you want a random integer between 0 and 10 do this
Java: | int x = (int)11*Math.random(); |
or a random integer between 15 and 30:
Java: | int x = 15 + (int)16*Math.random(); |
its 11 and 16 not 10 and 15 because (int)10.99999999999999999999999999 = 10 |
|
|
|
|
 |
abogaida
|
Posted: Wed Apr 08, 2009 4:44 pm Post subject: RE:Program help? |
|
|
Thanks a lot guys! |
|
|
|
|
 |
|