wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green Tutorial Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green Tutorial" Watch "Marcus Green Tutorial" New topic

Marcus Green Tutorial

Mahesh Bansal
Ranch Hand

Joined: Nov 28, 2000
Posts: 82
Which of the following will output a random with values only from 1 to 10 ?
1) System.out.println(Math.round(Math.random()*10));
2) System.out.println(Math.round(Math.random()%10));
3) System.out.println(Math.random()*10);
4) None of the above
The answer given is 4 can anyone please explain and what does random number means between 0.0 to 1.0 or beyond also.

Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
As far as I know, random is a method in java.lang.Math clas which generates a random number between 0.0 and 1.0 and returns it as a double value. And in plain english, it picks a number from 0.0 to 1.0 randomly.(which ever it feels like).
Tualha Khan

SCJP2, BEA WLS 6.0, DB2 UDB 7.1
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
yes. it can pick up any value from 0.0 to 1.0. when it does so, it can pick values < .1
applying this logic, u can come up withanswer for the above post as option 4.

Sun Certified Programmer for Java 2 Platform
Shrini Kulkarni
Ranch Hand

Joined: Jan 12, 2001
Posts: 63
what is the way to generate random numbers between 1 and 10 ?

Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Marcus Green Tutorial
It's not a secret anymore!