Page 426 - CA_Blue( J )_Class10
P. 426
7 String str;
8 int i,l,cw=0,ca=0,cd=0;
9 char ch;
10 System.out.print("Enter a sentence : ");
11 str=sc.nextLine();
12 l=str.length();
13 for(i=0;i<l;i++)
14 {
15 ch=str.charAt(i);
16 if(ch==' ')
17 {
18 cw++;
19 }
20 if((ch>='A' && ch<='Z') ||(ch>='a' && ch<='z'))
21 {
22 ca++;
23 }
24 if(ch>='0' && ch<='9')
25 {
26 cd++;
27 }
28 }
29 System.out.println("Number of words : "+(cw+1));
30 System.out.println("Number of alphabets : " + ca);
31 System.out.println("Number of digits : "+cd);
32 }
33 }
Program 2 To input a sentence, and convert the small letters to capital letters and vice versa. (Toggle Case)
1 import java.util.*;
2 class word_count
3 {
4 public static void main()
5 {
424424 Touchpad Computer Applications-X

