Question: Using Java, use recursion to write a method: int countLetter(String s, char c) which returns the number of times the letter c occurs in the

Using Java, use recursion to write a method: int countLetter(String s, char c) which returns the number of times the letter c occurs in the string s. For instance: countLetter("hi there", 'h') should be 2 countLetter("Mississippi", 'i') should be 4 countLetter("Marquette", 's') should be 0 To help with your recursive design, remember that a non-empty string S can be separated into a first letter, say F, and a substring of the remaining letters, say R. Then, the number of times a character c occurs in S is equal to countLetter(R, c) if c is not equal to F and is 1 + countLetter(R, c) if c *is* equal to F. write a simple test driver which reads a string and a character and prints the count.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!