Java Reference
In-Depth Information
58
59// Every word has at least one syllable
60 if (count == 0)
61 count = 1;
62 return count;
63 }
64
65 private String text;
66 }
268
269
Here is a simple test class. Type in a sentence, and the syllable counts of all words are
displayed.
ch06/debugger/SyllableCounter.java
1 import java.util.Scanner;
2
3 /**
4This program counts the syllables of all words in a sentence.
5 */
6 public class SyllableCounter
7 {
8 public static void main(String[] args)
9 {
10 Scanner in = new
Scanner(System.in);
11
12 System.out.println(ÐEnter a
sentence ending in a period.Ñ);
13
14 String input;
15 do
16 {
17 input = in.next();
18 Word w = new Word(input);
19 int syllables =
w.countSyllables();
20 System.out.println(ÐSyllables
in Ñ + input + Ð:Ñ
21 + syllables);
22 }
23 while (!input.endsWith(Ð.Ñ));
24 }
25 }
Search WWH ::




Custom Search