• 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

Marcus Green Tutorial

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Thanks

Mahesh
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
Bye,
Tualha Khan
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the way to generate random numbers between 1 and 10 ?
Bye
Shrinivas
reply
    Bookmark Topic Watch Topic
  • New Topic