• Post Reply Bookmark Topic Watch Topic
  • New Topic

Syllable counter  RSS feed

 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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!
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And which lone is that error on?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 17, what happens when i == 0?
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
It compiles right, but when I write a word it crashes.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
 
Liutauras Vilda
Sheriff
Posts: 4914
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!