Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Program help?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
abogaida




PostPosted: 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
Sponsor
sponsor
jbking




PostPosted: Wed Apr 08, 2009 3:25 pm   Post subject: Re: Program help?

Have you looked at any of the following resources about Java's built in Random class and methods?

http://www.javapractices.com/topic/TopicAction.do?Id=62
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html
http://www.cs.geneseo.edu/~baldwin/reference/random.html
matt271




PostPosted: 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




PostPosted: Wed Apr 08, 2009 4:44 pm   Post subject: RE:Program help?

Thanks a lot guys!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: