Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Random method
Venkat Ramsimha
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class RandomTest13
{
public static void main(
String
[] args)
{
for (int x=0; x < 15; x++)
System.out.print( (int)(Math.random()*10) + " " );
}
}
Hi All,
can anybody give the explanation as how the output is generated
thanks
venkat
Saranyan Narayanan
Ranch Hand
Posts: 34
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Random numbers can be from 0.0 to 1.0 , 1.0 not inclusive
Hence a set of random numbers would be displayed beween 1 - 9 in value , depending on ur number of iterations
Frederik Ericsson
Ranch Hand
Posts: 128
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi venkat,
-- (int)(Math.random()*10)
Math.random() -- this will generate random numbers between 0 and 1.
Ex: 0.8981130256628339 0.6494045787369 0.5306433259730561 0.8957299012137927
Math.random()*10 -- this will give
EX: 8.981130256628339 6.494045787369 5.306433259730561 8.957299012137927
(int)(Math.random()*10) -- this will type cast the values as int. so v ll get
Ex: 8 6 5 8
Make a note that random numbers will generate different values for every compile.
with regards,
Sethu.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Methods
initialisation and reinitialisation doubt.....
a question about static clause
why is the below code not printing 2 i agree its a post increment but its being assigned to x???
[Mock exam question][JSP script]
More...