In this video, length(), charAt() and trime() methods of String class are discussed with the help of 3 programs. Counting spaces with the help of all three methods is discussed in one program.
Link to the Book - Essentials of Computer Applications:
https://www.amazon.in/Essentials-Comp...
Practice exercise: Lesson 60 length(), charAt() and trim() methods of String
Length()
1. Read a String from user and display its length.
2. Read two Strings from user and display whether both are of equal length or not (use trim method).
3. Guess output of the following program.
a) int a = “pen drive”.length(); System.out.println(a);
b) System.out.println(“CD ROM”.length());
charAt()
4. Read a string and display each character in a separate line using charAt() method of String class.
5. Read a String from the user and display the last and first characters.
6. Read a String from the user and display count of words.
7. Read a name from the user and display only initials.
E.g., If the string is “Bala Murali Krishna”, the output must be B M K.