Problem Statement
Some texts contain hidden messages. In the context of this problem, the hidden message of a text is composed of the first letter from each word in the text, in the order they appear.
Given a String text, consisting of only lowercase letters and spaces, return the hidden message. A word is a maximal sequence of consecutive letters. There may be multiple spaces between words. Also, text may contain only spaces.
Definition
- Class:
- HiddenMessage
- Method:
- getMessage
- Parameters:
- String
- Returns:
- String
- Method signature:
- String getMessage(String text)
- (be sure your method is public)
Constraints
- text will contain between 1 and 50 characters, inclusive.
- Each character of text will be either a lowercase letter ('a'-'z'), or a space (' ').
Examples
"compete online design event rating"
Returns: "coder"
Taking the first letter from each word yields the return "coder"." c o d e r "
Returns: "coder"
Watch out for the leading spaces."round elimination during onsite contest"
Returns: "redoc"
"coder" written backwards." "
Returns: ""
Since there are no words here, the empty string must be returned.