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
- Print the first and last character of each word in a String
- Capitalize the first and last character of each word in a string
- Remove the first and last character of each word in a string
- Print the string after the specified character has occurred given no. of times
- Print Kth character in sorted concatenated substrings of a string
- Print the string by ignoring alternate occurrences of any character
- Replace every character of string by character whose ASCII value is K times more than it
- Find a string such that every character is lexicographically greater than its immediate next character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Replace every character of a string by a different character
- 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 list items containing all characters of a given word
- Print longest palindrome word in a sentence
- Print each word in a sentence with their corresponding average of ASCII values
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.