Question

Lab Description Take a string and remove all occurrences of the word chicken and count how many chickens were removed. Keep iimport static java.lang.System.* public class Recursion FunTwo public static int countChickens (String word) return 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class RecursionFunTwo {

    public static int countChickens(String word) {
        if (word.isEmpty()) {
            return 0;
        } else {
            int count = countChickens(word.substring(1));
            if (word.startsWith("chicken")) {
                ++count;
            }
            return count;
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Lab Description Take a string and remove all occurrences of the word chicken and count how...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT