wood burning stoves 2.0*
The moose likes Java in General and the fly likes what is wrong in this code ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is wrong in this code ?" Watch "what is wrong in this code ?" New topic
Author

what is wrong in this code ?

lp
Ranch Hand

Joined: Nov 08, 2000
Posts: 52
i have been getting an error while i am running this code
for(m=1;m<j+1;m++)
{
if((c[m]>100))
count=(count+1);
}
on the line where the count varaible is incremented .Please ket me know
bye
Thanks
Lakshmi
Elizabeth Lester
Ranch Hand

Joined: Aug 14, 2001
Posts: 129
What is the error you are getting?
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
It's impossible to say with the code snipet you have provided. If I just try to copy your code as is, NONE of your variables have any declared types, so the compiler complains about all of them. But I don't know if this is your problem because I don't know if or how you have declared your variables. Please post your code in the complete context, so it compiles, then I can answer you better.


Rob
SCJP 1.4
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
At a guess though, chances are good that you're getting an ArrayIndexOutOfBoundsException from c[m], since there doesn't appear to be bounds checking on this. (Unless j+1 is the size of array c.) You might want to put proper bounds checking into the loop:
for(m = 1; m < j + 1 && m < c.length; m++)
Incidentally, arrays start at index 0, not 1, so there's a good chance you want to start with m = 0 rather than m = 1.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is wrong in this code ?