Re: Random number
- From: Frank Stallone <askMe@xxxxxxxxxxx>
- Date: Sun, 06 Apr 2008 15:12:26 -0500
On Wed, 07 Feb 2007 00:03:54 +0000, Christo wrote:
hello I am new to java very new and am hoping someone can offer me someHere would be a way to do a random number between 1 and 50
help.
I know that i need to use java.util.Random somewhere to generate a
random number
can anyone show me the code to do this very basic code to simply output
the random number that has been generated to the console?
I would really appreciate this, I can work from there to expand on what
i need ti to do
TIA
Christo
here is math in the java API to help you understand how floor and random,
etc work:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html
public class MyRandomNumbers {
public static void main(String[] args) {
int myNumber;
myNumber = (int) Math.floor(Math.random() * 50 + 1);
System.out.println(myNumber);
}
}
Then again with it being over a year later, I hope you're past this
point. ;)
.
- Prev by Date: Re: Declining Popularity of Java?
- Next by Date: Newb Naming Convention Question
- Previous by thread: Re: Declining Popularity of Java?
- Next by thread: Newb Naming Convention Question
- Index(es):