• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong in this code ?

 
lp
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error you are getting?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic