Question: Write a static method named favoriteLetter that accepts two parameters : a Scanner from the console, and a favorite letter represented as a one-letter String.

Write a static method named favoriteLetter that accepts two parameters: a Scanner from the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed.

You may assume that the user will type single-word responses to each prompt. Your code should be case-sensitive, (if the favorite letter is a, you should not stop prompting if the user types words that start with a capital A.

The following represents output from two calls to your method:

(User input is underlined.)

Call

Scanner console = new Scanner(System.in);

favoriteLetter(console, "y");

Scanner console = new Scanner(System.in);

favoriteLetter(console, "A");

Output

Looking for two "y" words in a row.

Type a word: hi

Type a word: bye

Type a word: yes

Type a word: what?

Type a word: yellow

Type a word: yippee

"y" is for "yippee"

Looking for two "A" words in a row.

Type a word: I

Type a word: love

Type a word: COSC236!

Type a word: AND

Type a word: PROGRAMS

Type a word: are

Type a word: always

Type a word: Absolutely

Type a word: Awesome

"A" is for "Awesome

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!