Given a string, the task is to print the first and last character of each word in a string.
Input: Geeks for geeks Output: Gs fr gs Input: Computer applications Output: Cr as
- Run a loop from the first letter to the last letter.
- Print the first and last letter of the string.
- If there is a space in the string then print the character that lies just before space and just after space.
Below is the implementation of the above approach.
Gs fr Gs
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Remove the first and last character of each word in a string
- Capitalize the first and last character of each word in a string
- Print last character of each word in a string
- Reverse every word of the string except the first and the last character
- Modify string by increasing each character by its distance from the end of the word
- Get the first letter of each word in a string using regex in Java
- Remove the first and last occurrence of a given Character from a String
- How to find the first and last character of a string in Java
- Remove first and last character of a string in Java
- Swap the first and last character of a string in Java
- Print the last character of lexicographically smallest non-palindromic permutation of a string
- Count of substrings having the most frequent character in the string as first character
- Minimum operation require to make first and last character same
- C program to find and replace a word in a File by another given word
- Length Of Last Word in a String
- String containing first letter of every word in a given string with spaces
- Most frequent word in first String which is not present in second String
- Print each word in a sentence with their corresponding average of ASCII values
- Queries to find the last non-repeating character in the sub-string of a given string
- Longest Common Prefix using Word by Word Matching
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.