Computer Science Canada Generating Multiple Random Numbers |
Author: | Flashkicks [ Thu Feb 10, 2005 1:35 pm ] | ||
Post subject: | Generating Multiple Random Numbers | ||
This is an assignment I have, and the following is the coding. I can not get the "generate 5 random numbers between 1-10" part. [Just ignore the other stuff.. sqrRoot, absolute..etc..] Any help would be nice. I have my program to work, yes; but I think java should be far more capable of figuring out mulitple values in one line rather than having to write it out 5 times. I mean, even Turing just simply uses a for statement.. Can someone tell me how I would use a "for statement" for this?
~Flashkicks |
Author: | Tony [ Thu Feb 10, 2005 1:40 pm ] | ||
Post subject: | |||
btw, if you want all 5 digits in a single statement, you can pick a random numbet between (10000 and 99999) and split it up by digits |
Author: | Flashkicks [ Thu Feb 10, 2005 1:49 pm ] |
Post subject: | |
Wow I think thats the fastest reply Iv ever seen .. Thanks once again Tony. Your the man ..lol. I shall go try it and I think it will work. I was just playing around with the for loops myself but I couldnt get it to work. So then I tried something called a "while loop" or something.. Still no luck.. But thanks man! I appreciate it! ~Flashkicks :: UpDated :: Okay- Tony. I am sorry but it is still not working.. Says randomValue is not an array type. I changed it to int and whatnot [also got rid of the randomValue1, and randomValue2 etc] and nothing will work.. Do you think you could try editing it into my program?. I am sorry to bug you. I shall keep trying.. ::: UpDated AGAIN ::: Okay I am sorry to do this but I got it to work.. It was very simple. however, if you look below I am supposed to now do between 11-95 .. THAT--is where I am stuck. I pulled out the ol' reference book and everything. So please.. Someone help..lol This is why i hate Java. Iv always hated Java and I still say its EVIL!!! |
Author: | Tony [ Thu Feb 10, 2005 3:21 pm ] | ||
Post subject: | |||
|
Author: | wtd [ Thu Feb 10, 2005 3:57 pm ] | ||||
Post subject: | |||||
tony wrote:
That's just asking for problems. There's only room for 4 values in that array, but you run the loop 5 times.
|
Author: | Tony [ Thu Feb 10, 2005 4:28 pm ] |
Post subject: | |
aren't Java arrays 0-index? (0,1,2,3,4 ~ 5 elements). anyways, wtd knows what he's doing. I'm just stabbing in the dark (haven't actually done any Java or even C++ for that matter in a while) |
Author: | wtd [ Thu Feb 10, 2005 4:42 pm ] | ||
Post subject: | |||
tony wrote: aren't Java arrays 0-index? (0,1,2,3,4 ~ 5 elements).
Yes, but the number you give in the declaration/initialization is the capacity of the array, not the last index. Of course, I'd still prefer Ruby.
|
Author: | Flashkicks [ Fri Feb 11, 2005 10:14 am ] | ||
Post subject: | |||
Kay I tried all of your guys' stuff and some of it wasa a bit complicating, while other stuff did kinda work.. So I took your coding and changed it a tad bit and now I got it working. Heres what I used:
And this did the job fiiine Thanks for all your help~ ~Flashkicks |
Author: | wtd [ Fri Feb 11, 2005 2:59 pm ] | ||||
Post subject: | |||||
Flashkicks wrote: Kay I tried all of your guys' stuff and some of it wasa a bit complicating, while other stuff did kinda work.. So I took your coding and changed it a tad bit and now I got it working. Heres what I used:
And this did the job fiiine Thanks for all your help~ ~Flashkicks Note: while it may be good Turing style to put space between a function/procedure and the parens that follow it, the more generally accepted style for Java/C/C++/etc. is for there to be no space. Additionally, you can remove a number of parens due to the order of operations. Multiplication is performed first, then addition.
|