Given a string str, the task is to print the last character of each word in the string.
Input: str = “Geeks for Geeks”
Output: s r s
Input: str = “computer applications”
Output: r s
Approach: Append a space i.e. ” “ at the end of the given string so that the last word in the string is also followed by a space just like all the other words in the string. Now start traversing the string character by character, and print every character which is followed by a space.
Below is the implementation of the above approach:
s r s
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.
- Print the first and last character of each word in a String
- Remove the first and last character of each word in a string
- Capitalize the first and 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
- Print the last character of lexicographically smallest non-palindromic permutation of a string
- Length Of Last Word in a String
- Java Program to find the Last Index of a Particular Word in a 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
- C program to Replace a word in a text by another given word
- C program to find and replace a word in a File by another given word
- Find the word from a given sentence having given word as prefix
- Get the first letter of each word in a string using regex in Java
- Find frequency of each word in a string in Python
- Calculate the frequency of each word in the given string
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Lengths of maximized partitions of a string such that each character of the string appears in one substring
- Maximized partitions of a string such that each character of the string appears in one substring
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.