• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Syllable counter

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

I'm really desperate!
So in this program I have to count the number of syllabels based on the following heuristics:

Count up the number of vowels in the word (including 'y'), except for
• Vowels that have vowels directly before them, and
• The letter e, if it appears by itself at the end of a word.



My code is always getting an error "String.charAt(int) line: not available for the line"



Thanks for the help!
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And which lone is that error on?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On line 17, what happens when i == 0?
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:On line 17, what happens when i == 0?



I think the problem is there, I just don't know how to come around it

Campbell Ritchie wrote: And which lone is that error on?



Line 18
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There most certainly is a charAt(int) method. I suggest you follow that link and copy and paste the name of the method just in case there is a strange spelling error.

I copied and pasted your code and it compiled all right for me.
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles right, but when I write a word it crashes.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Ribeiro wrote:It compiles right, but when I write a word it crashes.



First, you have to give more details than "crashes". This really doesn't help us. And you should want to help us help you.


Anyway, as you already figured out, the issue is that you are doing a charAt(i-1) method call, and when the variable "i" is zero, the expression tries to retrieve the character at index negative one, which does not exist.

The answer is simply "don't do that". This is an edge condition -- meaning the edge of the loop (index zero) is handled slightly differently than the rest of the loop. Now, you can try to figure out an algorithm that takes care of the edge too. Or you can simply take care of index zero first (and separately) from the loop, and then modify your loop to start at index one.

Henry
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Ribeiro wrote:It compiles right, but when I write a word it crashes.

Hi Bruno,
Have you tried to think about the case, when "i = 0"
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry Henry, you are right. Since I'm not with the program at the moment I can't specify much more. I'll be more careful in the future.

I thought about what you recommended (use another loop that starts at one). I will try that later and come back too you.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is the error message? Is it the same as Junilu predicted yesterday?

I see others have already hinted that.
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved the problem with the help or Henry tips. Thank you everyone for your advices, and sorry for not being specific, I still have to learn how to work with tghe debugging system and learn more technical terms so I can help you help me.

The final code (I know its messy, if you got any advices about how to shorten it I would be most grateful!):



Have a nice weekend!
Bruno
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnks for this code is it also work for different language also....
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashish, your syllable counter thinks that "flavour" has zero syllables.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic