Page 244 - Computer science 868 Class 12
P. 244
4. Character.isWhitespace(‘ch’): This method is used to check whether the character in the argument is a space or not.
System.out.println(Character.isWhitespace ('4')); // Output: false
5. Character.isUpperCase(char): This method is used to check whether the parameter passed is in capital letters or
not and returns true if satisfied, else returns zero.
//Output: true
boolean b = Character.isUpperCase ('A');
6. Character.isLowerCase(char): This method is used to check whether the parameter passed is in small letters and
returns true if satisfied, else returns zero.
boolean b = Character.isLowerCase ('A'); // Output: false
7. Character.toUpperCase(char): This method converts the character passed as argument to capital letter if it is in
small letter, else returns the same argument passed.
boolean b = Character.toUpperCase ('a'); // Output: A
8. Character.toLowerCase(char): This method converts the character passed as argument to small letter if it is in
capital letter, else returns the same argument passed.
boolean b = Character.toLowerCase ('a'); // Output: a
8.10 PROGRAMS USING CHARACTER METHODS
Program 2 Write a program to input a sentence and print the count of the following
a. Number of capital letters
b. Number of small letters
c. Number of digits
1 import java.util.*;
2 class count
3 {
4 public static void main()
5 {
6 Scanner sc=new Scanner(System.in);
7 String str;
8 int i, len, cc=0,cs=0,cd=0;
9 char ch;
10 System.out.println("Enter a sentence : ");
11 str=sc.nextLine();
12 len=str.length();
13 for(i=0;i<len;i++)
14 {
15 ch=str.charAt(i);
16 if(Character.isUpperCase(ch))
17 {
18 cc++;
242242 Touchpad Computer Science-XII

