This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
sudde gameeef wrote:i am making a game where i need to create object only onces randomly. <br/>
i can get random number by random object. but not sure how to put in if statment. <br/>
I'm not sure I understand the question. Are you sure you've read and understood the java.util.Random API? (and BTW, it's 'Random', not 'random' - that sort of stuff is very important in Java).
The reason I ask is that I don't see any attempt to call one of its methods in your code.
Normally, I'd suggest using the online tutorials; but unfortunately they still seem to be stuck on using Math.random(), which is vastly inferior to the Random class. This page seems to provide a quick intro with a few examples though.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ramesh Pramuditha Rathnayake wrote:This will give the same result as in yours. But this contains no unnecessary codes...
Almost the same. The original code didn't print anything if x was exactly equal to 0, 100 or 200. Also, the condition (x < 300) is unnecessary, because r.nextInt(300) will always produce a number less than 300.
Jesper de Jong wrote:Almost the same. The original code didn't print anything if x was exactly equal to 0, 100 or 200. Also, the condition (x < 300) is unnecessary, because r.nextInt(300) will always produce a number less than 300.
You are right..!
I have done a greate mistake..!!!