• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

what is wrong in this code ?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error you are getting?
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic