Re: Random number



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 some
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 would be a way to do a random number between 1 and 50

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. ;)
.