120k views
4 votes
For this exercise, you are given a phrase. Return the number of time the word “dog” appears in the phrase.

Example:

countDog("dogs are good") --> 1
countDog("my dog does not like hot dogs") --> 2

This is in Java.

1 Answer

2 votes

Answer:

Is in the provided screenshot!

Step-by-step explanation:

Steps needed to solve this problem.

1) Split the input string into separate words

2) Filter the words to ones that match "dog"

3) Count how many words are left - as these are all the ones that say dog.

4) Return the value needed!

For this exercise, you are given a phrase. Return the number of time the word “dog-example-1
User Francene
by
5.8k points