Page 75 - CTS - CSA TP - Volume 2
P. 75

COMPUTER SOFTWARE APPLICATION - CITS




           EXERCISE 91 : Use the JAVA character class methods



           Objectives

           At the end of this exercise you shall be able to
           •    know more about  the use of character class methods in Java
           •    develop Java programs using character class methods.

           Requirements

           Tools/Materials
           •  PC/Laptop  with Windows OS
           •  JDK Software
           •  Text editor (Visual studio / Sublime / Note pad)


           Procedure

           Here are some examples demonstrating the use of various methods in the Character class in Java:
           TASK 1: Check if a Character is a Letter or Digit
              public class CharacterExample1 {
               public static void main(String[] args) {

                   char ch1 = ‘A’;
                   char ch2 = ‘5’;


                   System.out.println(ch1 + “ is a letter: “ + Character.isLetter(ch1));

                   System.out.println(ch2 + “ is a digit: “ + Character.isDigit(ch2));
               }
           }


           Output;































                                                           60
   70   71   72   73   74   75   76   77   78   79   80