Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2009, 08:21 AM
Member
 
Join Date: Jan 2009
Posts: 22
Rep Power: 0
PeterFeng is on a distinguished road
Default Random Numbersz?
public class mainMemory {

public static void main(String[] args) {
int frag1=100, frag2=200, frag3=300, frag4 ;
frag4=frag1+frag2+frag3;
// TODO, add your application code
System.out.println("Internal Frag: " +frag4 +" Kb");
}


}


Hi, I need a little help here, as u can see from the code above, frag4 is the combination of frag1+frag2+frag3. How do I set a random number to frag1, frag2, frag3? in addition the random number must not be greater than 999
Bookmark Post in Technorati
  #2 (permalink)  
Old 01-13-2009, 08:31 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,454
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Did you read anything about random numbers on the web.

Read this page
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
  #3 (permalink)  
Old 01-13-2009, 08:32 AM
Member
 
Join Date: Jan 2009
Posts: 22
Rep Power: 0
PeterFeng is on a distinguished road
Default
dun really understand what they meant. any good webbies that i could have hands on?
I'll repost this in right forums

Last edited by PeterFeng; 01-13-2009 at 08:42 AM.
Bookmark Post in Technorati
  #4 (permalink)  
Old 01-13-2009, 08:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,454
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
All what you need are there at the time. Or else go to the Suns' tutorial.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
  #5 (permalink)  
Old 01-13-2009, 12:24 PM
Senior Member
 
Join Date: Nov 2008
Posts: 275
Rep Power: 2
neilcoffey is on a distinguished road
Default
See the java.util.Random class. I also have a few web pages discussing random numbers in Java, and some pitfalls to be aware of.

The main thing that people get wrong when they use the Random class (and actually various other classes) is simply that they make things up rather than reading the documentation. Typical things that people get wrong:
- they create a new Random object for every single random number they need; don't do that: instead, create a single Random object and re-use it
- they don't use the appropriate method; for example, if you need a number between 0 and 1000, then call nextInt(1000): do not do the following

Code:
// This is WRONG!!
int n = Math.abs(r.nextInt()) % 1000;
__________________
Neil Coffey
Javamex - Java tutorials and performance info
Bookmark Post in Technorati
  #6 (permalink)  
Old 01-13-2009, 01:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,454
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
No need to re-post your question again. Please hang on with this.

And also search our forum. This question we have discussed several times.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I generate random numbers in a certain range using the random class? frasifrasi New To Java 8 04-19-2009 06:50 PM
Random koolhoney New To Java 11 09-30-2008 04:39 AM
Using Random razmyasdfg CLDC and MIDP 1 07-27-2008 11:47 PM
random numbers without random class` carlos123 New To Java 4 01-17-2008 11:44 PM
Math.Random Java Tip Java Tips 0 11-23-2007 03:09 PM


All times are GMT +2. The time now is 06:37 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org