Page 369 - Computer science 868 Class 12
P. 369
18 boolean isCap(String w)
19 {
20 char ch = w.charAt(0);
21 if(Character.isLetter(ch) && Character.isUpperCase(ch))
22 return true;
23 else
24 return false;
25 }
26
27 void display()
28 {
29 StringTokenizer st = new StringTokenizer(sent, " , ?!");
30 int count = st.countTokens();
31 for(int i = 1; i<= count; i++)
32 {
33 String word = st.nextToken();
34 if(isCap(word))
35 freq++;
36 }
37 System.out.println("Sentence: " + sent);
38 System.out.println("Frequency of words beginning with capital letter: " + freq);
39 }
40
41 public static void main(String args[])
42 {
43 Capital obj = new Capital();
44 obj.input();
45 obj.display();
46 }
47 }
The output of the preceding program is as follows:
Enter the sentence: I Am going to School
367
Strings 367

