Java Reference
In-Depth Information
19 /**
20Returns the text of the word, after removal of the
21leading and trailing nonletter characters.
22 @return the text of the word
23 */
24 public String getText()
25 {
26 return text;
27 }
28
29 /**
30Counts the syllables in the word.
31 @return the syllable count
32 */
33 public int countSyllables()
34 {
35 int count = 0;
36 int end = text.length() - 1;
37 if (end < 0) return 0; // The empty string has
no syllables
38
39 // An e at the end of the word doesn't
count as a vowel
40 char ch =
Character.toLowerCase(text.charAt(end));
41 if (ch == ÒeÓ) end--
42
43 boolean insideVowelGroup = false;
44 for (int i = 0; i <= end; i++)
45 {
46 ch =
Character.toLowerCase(text.charAt(i));
47 if (ÐaeiouyÑ.index0f(ch) >= 0)
48 {
49 // ch is a vowel
50 if (!insideVowelGroup)
51 {
52// Start of new vowel group
53 count++;
54 insideVowelGroup = true;
55 }
56 }
57 }
Search WWH ::




Custom Search