Problem Statement
You will be a given a String text and a String part. You will return an int representing how many times part occurs in text as a substring. For example:
text = "aaaabbbb"
text = "aaaabbbb"
- If part = "ab" then you would return 1 since ab occurs only once in text.
- If part = "aa" then you would return 3 since there are 3 distinct occurrences of aa in text.
- If part = "aaa" then you would return 2 since there are 2 distinct occurrences of aaa in text.
- If part = "ba" then you would return 0 since ba does not occur in text.
Definition
- Class:
- StringFind
- Method:
- howMany
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int howMany(String text, String part)
- (be sure your method is public)
Constraints
- text will contain between 1 and 50 characters inclusive.
- Each character in text will be a lowercase letter ('a'-'z').
- part will contain between 1 and 50 characters inclusive.
- Each character in part will be a lowercase letter ('a'-'z').
Examples
"aaaabbbb"
"ab"
Returns: 1
From above"aaaabbbb"
"aa"
Returns: 3
From above"ladidadi"
"z"
Returns: 0
No z's here"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aa"
Returns: 49
Lots of a's