Problem Statement
A sentence is called dancing if its first letter is uppercase and the case of each subsequent letter is the opposite of the previous letter. Spaces should be ignored when determining the case of a letter. For example, "A b Cd" is a dancing sentence because the first letter ('A') is uppercase, the next letter ('b') is lowercase, the next letter ('C') is uppercase, and the next letter ('d') is lowercase.
You will be given a String sentence. Turn the sentence into a dancing sentence by changing the cases of the letters where necessary. All spaces in the original sentence must be preserved.
Definition
- Class:
- DancingSentence
- Method:
- makeDancing
- Parameters:
- String
- Returns:
- String
- Method signature:
- String makeDancing(String sentence)
- (be sure your method is public)
Constraints
- sentence will contain between 1 and 50 characters, inclusive.
- Each character in sentence will be a letter ('A'-'Z','a'-'z') or a space (' ').
- sentence will contain at least one letter ('A'-'Z','a'-'z').
Examples
"This is a dancing sentence"
Returns: "ThIs Is A dAnCiNg SeNtEnCe"
" This is a dancing sentence "
Returns: " ThIs Is A dAnCiNg SeNtEnCe "
Spaces should be ignored when determining the cases of the letters, but they should be preserved in the return value."aaaaaaaaaaa"
Returns: "AaAaAaAaAaA"
"z"
Returns: "Z"