Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Random Number Generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random Number Generator" Watch "Random Number Generator" New topic
Author

Random Number Generator

Tarrell Fletcher
Ranch Hand

Joined: Oct 07, 2011
Posts: 60
I am having problems storing floating point numbers from a random number generator. I can store it once but its when i have to iterate it that the problem comes in.



I have to cut that randomly generated number at the 3rd, 4th, 5th and 6th decimal. Then store it as I go in a variable and lastly have it add up to show the accumulated total through iterations. I have to do 10, 100, 1,000 and 10,000 reps. I am just trying to make the method and then pass the randomly generated number as an argument. I am just having a problem getting the total without actually showing all the work. Its like the variable will be out of scope I think.
Jeff Kendall
Greenhorn

Joined: Aug 19, 2011
Posts: 4
Your truncation should be outside of your main method body. I don't see where you are totaling your numbers and if you are trying to keep a running total your function should probably be returning a value instead of being void.
Tarrell Fletcher
Ranch Hand

Joined: Oct 07, 2011
Posts: 60
I thought void was just to let me make the method ?_?. Wait wait wait...so I need something like



Should it be like that? But I thought you could only return one thing. But I need to return the sums of the 3th, 4th, 5th and 6th. Like as it accumulates the 3th decimal numbers should be adding with the newly found 3th decimal and the 4th should do the same and so on.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

You can only return one thing. But, that thing could be an array, or an object that is a collection of other things...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random Number Generator