Computer Science Canada Issue with storing to Array |
Author: | chromium [ Thu Apr 03, 2014 7:30 pm ] | ||
Post subject: | Issue with storing to Array | ||
Im trying to populate an array using a for loop. Here is my code:
My problem is with the expPopArray. When I leave the print line inside of the for loop (the line i commented out), it returns the correct values. However if I try to print the array from outside of the loop it always returns 0. I need to be able to access the array from outside of the loop. Can someone tell me where im going wrong? Thanks. |
Author: | Dreadnought [ Thu Apr 03, 2014 8:10 pm ] | ||
Post subject: | Re: Issue with storing to Array | ||
I'm not a java guy but this caught my eye
I'm pretty sure this creates a new array of 25 doubles. So every time you go through the loop you make a new array (throwing away the old one) and store expPop at the ith position. You probably want to create your array outside the loop and then populate it with values. |
Author: | chromium [ Fri Apr 04, 2014 6:16 am ] | ||
Post subject: | Re: Issue with storing to Array | ||
Dreadnought @ Thu Apr 03, 2014 8:10 pm wrote: I'm not a java guy but this caught my eye
I'm pretty sure this creates a new array of 25 doubles. So every time you go through the loop you make a new array (throwing away the old one) and store expPop at the ith position. You probably want to create your array outside the loop and then populate it with values. Thanks, that was the problem. |