Given a sentence, task is to remove spaces from the sentence and rewrite in Camel case. It is a style of writing where we don’t have spaces and all words begin with capital letters.
Input : I got intern at geeksforgeeks Output : IGotInternAtGeeksforgeeks Input : Here comes the garden Output : HereComesTheGarden
Simple solution: First method is to traverse sentence and one by one remove spaces by moving subsequent characters one position back and changing case of first character to capital. It takes O(n*n) time.
Efficient solution : We traverse given string, while traversing we copy non space character to result and whenever we encounter space, we ignore it and change next letter to capital.
Below is code implementation
This article is contributed by Himanshu Ranjan. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Sentence Case of a given Camel cased string
- Convert camel case string to snake case in Java
- Convert Snake Case string to Camel Case in Java
- Extract and print words separately from a given Camel Case string
- gOOGLE cASE of a given sentence
- Snake case of a given sentence
- Frequency of smallest character in first sentence less than that of second sentence
- Lower case to upper case - An interesting fact
- Check a given sentence for a given set of simple grammer rules
- Find the word from a given sentence having given word as prefix
- Java program to count the characters in each word in a given sentence
- Find the word with most anagrams in a given sentence
- Remove all the palindromic words from the given sentence
- Print given sentence into its equivalent ASCII form
- Convert vowels into upper case character in a given string
- Calculate the difficulty of a sentence
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Convert the ASCII value sentence to its equivalent string
- Java program to swap first and last characters of words in a sentence
- Program for length of the longest word in a sentence
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.