Page 79 - CITS - CSA - TP (Volume 2) - Hindi
P. 79

कं  ूटर सॉ वेयर ए ीके शन - CITS




           टा  3: िसंगल  ो ाम म  िविभ     ंग िविधयों को िन ािदत करने के  िलए Java  ो ाम
            public class StringMethodsExample {
              public static void main(String[] args) {

                   // Example String
                   String originalString = “Hello, World!”;

                    System.out.println(“Original String: “ + originalString);

                   // 1. Convert to Uppercase
                   String uppercaseString = originalString.toUpperCase();

                   System.out.println(“1. Uppercase: “ + uppercaseString);



                   // 2. Convert to Lowercase
                   String lowercaseString = originalString.toLowerCase();
                   System.out.println(“2. Lowercase: “ + lowercaseString);



                   // 3. Substring
                   String substring = originalString.substring(7, 12);

                   System.out.println(“3. Substring ( Display ‘World’ from the Original String): “ + substring);


                   // 4. Index of a Character

                   int indexOfW = originalString.indexOf(‘W’);
                   System.out.println(“4. Index of ‘W’ (index value start from 0): “ + indexOfW);



                   // 5. Replace characters
                   String replacedString = originalString.replace(‘o’, ‘X’);

                   System.out.println(“5. Replaced String ( Replacing ‘o’ with ‘X’):  “ + replacedString);


                   // 6. Check if starts with “Hello”

                   boolean startsWithHello = originalString.startsWith(“Hello”);
                   System.out.println(“6. Starts with ‘Hello’: “ + startsWithHello);



                   // 7. Check if ends with “World!”
                   boolean endsWithWorld = originalString.endsWith(“World!”);
                   System.out.println(“7. Ends with ‘World!’: “ + endsWithWorld);



                   // 8. Trim leading and trailing whitespaces
                   String stringWithWhitespaces = “   Trim Me   “;



                                                           65

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 92
   74   75   76   77   78   79   80   81   82   83   84