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

COMPUTER SOFTWARE APPLICATION - CITS




           TASK 2: Convert Uppercase to Lowercase and Vice Versa
             public class CharacterExample2 {
               public static void main(String[] args) {

                   char uppercaseChar = ‘H’;
                   // Convert to lowercase
                   char lowercaseChar = Character.toLowerCase(uppercaseChar);
                   System.out.println(“Uppercase: “ + uppercaseChar);

                   System.out.println(“Lowercase: “ + lowercaseChar);


                   // Convert back to uppercase
                   char originalUppercaseChar = Character.toUpperCase(lowercaseChar);
                   System.out.println(“Original Uppercase: “ + originalUppercaseChar);
               }

           }
           Output:















           TASK 3: Check if a Character is Uppercase or Lowercase
           public class CharacterExample3 {

               public static void main(String[] args) {
                   char ch1 = ‘a’;
                   char ch2 = ‘Z’;


                   System.out.println(ch1 + “ is uppercase: “ + Character.isUpperCase(ch1));

                   System.out.println(ch2 + “ is lowercase: “ + Character.isLowerCase(ch2));
               }
           }
           Output:

















                                                           61
                                CITS : IT & ITES - Computer Software Application - Exercise 91
   71   72   73   74   75   76   77   78   79   80   81