my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Random numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random numbers" Watch "Random numbers" New topic
Author

Random numbers

Imran Bhutta
Greenhorn

Joined: Oct 31, 2004
Posts: 9
i need help, if i need to create a random number that has 6 numbers and then has a negitive number how would i do that..

like
776289-6
743660-1
382938-3
548791-4

??? any suggestions? thanks
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Does the "negative part" consist of only a single digit? If so, I might view a String that can be parsed into two positive numbers separated by a dash (-). You may want to look at the random() method in the Math class. For more flexibility, you can use the Random class instead.

I'll let you look at the Java API docs (see the links above) and check out your text book for details in this area. If you generate the two numbers, you can use the Integer class to convert them to strings and concatenate them together.

HTH

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random numbers
 
Similar Threads
Which Swing component to use ?
print out random number and state odd/even
randon number
How do you print a character a random number of times?
Random Number Generator