Computer Science Canada Array index out of bounds |
Author: | umaster [ Mon Mar 24, 2008 12:59 pm ] | ||
Post subject: | Array index out of bounds | ||
Hey im pretty new to Java just started about 4 weeks ago and so far its ok some things are a bit confusing. Anywho i get this array index out of bounds exception = 5 error. I know that it is checking for a part of the array that doesn't exist but that is not possible seeing as how the loop on goes 5 times and there is definetly 5 values. I clearly am not seeing somthing and i need mores eyes to look at it from a different perspective maybe the problem can be found Here is my code:
|
Author: | syntax_error [ Mon Mar 24, 2008 1:11 pm ] | ||
Post subject: | Re: Array index out of bounds | ||
not totally sure here but shouldnt it be :
not sure tho... give it a try |
Author: | umaster [ Mon Mar 24, 2008 1:16 pm ] |
Post subject: | Re: Array index out of bounds |
ok i tried it and it ran but now at the end i put the third for loop to see if it was doing what i wanted it to do and im gettiong 0.0 when im tryign to display the averages |
Author: | HeavenAgain [ Mon Mar 24, 2008 1:22 pm ] | ||||||
Post subject: | RE:Array index out of bounds | ||||||
and now in your for loops you have
also another note, for your for loop, you can initialize variables within the first block, for example
|
Author: | umaster [ Mon Mar 24, 2008 1:26 pm ] | ||
Post subject: | Re: Array index out of bounds | ||
ok im not getting the array out of index anymore but now its not getting any values i changed it so that is is now:
and it runs but when is prints out the averages at the end apparently they are all 0.0 here are the results: Quote: deps-jar: Compiling 1 source file to C:\Documents and Settings\Gary2\My Documents\NetBeansProjects\JavaApplication3\build\classes compile: run: 0.0 0.0 0.0 0.0 BUILD SUCCESSFUL (total time: 0 seconds) |
Author: | syntax_error [ Mon Mar 24, 2008 1:36 pm ] | ||||
Post subject: | Re: Array index out of bounds | ||||
first of all I fixed your code made it cleaner [well imo]
your for loops you should do them as this
you are not going to use the var after the loop then why make it gobal? EDIT : btw i jsut fixed your code in the reply window do compile it and check it, might miss a semicolon or sometthing silly |
Author: | umaster [ Mon Mar 24, 2008 1:45 pm ] | ||
Post subject: | Re: Array index out of bounds | ||
ok i got it. It works now im getting real numbers and ive checked them and they work thank you guys Here is a refrence for those whow might have this problem in the future it is the fixed code:
|
Author: | syntax_error [ Mon Mar 24, 2008 1:51 pm ] | ||
Post subject: | Re: Array index out of bounds | ||
why do you need
|
Author: | wtd [ Mon Mar 24, 2008 2:29 pm ] | ||
Post subject: | RE:Array index out of bounds | ||
Even correct Hungarian notation makes Zombie Jesus cry. This isn't even correct Hungarian notation. |
Author: | umaster [ Wed Apr 02, 2008 12:58 pm ] |
Post subject: | Re: Array index out of bounds |
it was an assignment i wonly explained one part dont worry about the rest it works now |