Capitalize first and last letter of each word in a line | faceprep

Capitalize first and last letter of each word in a line | faceprep

Program to capitalize first and last letter of each word in a line is discussed here. The basic algorithm is to keep track of the spaces and capitalize the letter before the space and after space. The first letter and the last letter of the given line should be capitalized.


Capitalizing the first and last letter of each word in a Line




There are only a few things that need to be considered:

  • More than one occurrence of spaces between two words.
  • There can be a single word like ‘a’ that needs to be capitalized.
  • There may be two words like “me” where both letters must be capitalized.




Algorithm to capitalize first and last letter of each word in a line

  1. Get the String input.
  2. Iterate from i=0 to length-1.
  3. Find the index space in your string.
  4. Run a loop which will run till the length of the string.
  5. With the help of if else first convert the first letter of the sentence to uppercase if its capital uppercase it the way it is.
  6. With if else find space and covert the letter before and after to upper case.
  7. Print the converted line.



Program to capitalize first and last letter of each word in a line

@@coding::1@@




Recommended Programs



c