Java Reference
In-Depth Information
Supply this input:
hello yellow peach.
Then the output is
Syllables in hello: 1
Syllables in yellow: 1
Syllables in peach.: 1
That is not very promising.
First, set a breakpoint in the first line of the
countSyllables
method of the
Word
class, in line 33 of
Word.java
. Then start the program. The program will prompt
you for the input. The program will stop at the breakpoint you just set.
269
270
Figure 7
Debugging the
countSyllables
Method
First, the
countSyllables
method checks the last character of the word to see if
it is a letter
ÓeÓ
. Let's just verify that this works correctly. Run the program to line 41
(see
Figure 7
).
Now inspect the variable
ch
. This particular debugger has a handy display of all
current local and instance variablesȌsee
Figure 8
. If yours doesn't, you may need to
inspect
ch
manually. You can see that
ch
contains the value
ÓlÓ
. That is strange.
Look at the source code. The
end
variable was set to
text.length() - 1
, the
last position in the
text
string, and
ch
is the character at that position.