Problem Statement
We are looking for occurrences of the string "red" in a piece of text. For example, in the text
the detective questioned his credibility
we find "red" inside the word "credibility".
Capitalization doesn't matter, so in the text
Server ERRED in Redirecting Spam
we find "red" at the end of "ERRED", as well as at the beginning of "Redirecting".
Given a String, count the number of times "red" appears in it with any capitalization.
Definition
- Class:
- CodeRed
- Method:
- count
- Parameters:
- String
- Returns:
- int
- Method signature:
- int count(String text)
- (be sure your method is public)
Constraints
- text will contain between 1 and 50 characters, inclusive.
- text will contain only letters ('A'-'Z', 'a'-'z') and spaces (' ').
Examples
"the detective questioned his credibility"
Returns: 1
The first example from the problem statement."Server ERRED in Redirecting Spam"
Returns: 2
The second example from the problem statement." read the RED sign said fReD"
Returns: 2
"pure delight"
Returns: 0
Note that "re d" is not counted as an occurrence of "red"."re"
Returns: 0