Java Reference
In-Depth Information
271
Figure 9
Debugging the Word Constructor
At this point, inspecting i and j shows that i is 0 and j is 4. That makes senseȌ
there were no punctuation marks to skip. So why is text being set to ÑhellÑ ?
Recall that the substring method counts positions up to, but not including, the
second parameter. Thus, the correct call should be
text = s.substring(i, j + 1);
This is a very typical off-by-one error.
Search WWH ::




Custom Search