favoriteLetter
Category: Programming
Author: Marty Stepp and Benson Limketkai
Book Chapter: 4.3
Problem: favoriteLetter
Write a static method named favoriteLetter that accepts two parameters: a Scanner for 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 a single word of input as their response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is lowercase a, you should not stop prompting if the user types words that start with an uppercase A. For example, the following logs represent the output from two calls to your method: Call | Scanner console = new Scanner(System.in); | Scanner console = new Scanner(System.in); | favoriteLetter(console, "y"); | favoriteLetter(console, "A"); ---------------------------------------------------------------------------------------------------- Output | Looking for two "y" words in a row. | Looking for two "A" words in a row. | Type a word: hi | Type a word: I | Type a word: bye | Type a word: love | Type a word: yes | Type a word: CSE142 | Type a word: what? | Type a word: !!! | Type a word: yellow | Type a word: AND | Type a word: yippee | Type a word: PROGRAMS | "y" is for "yippee" | Type a word: are | | Type a word: always | | Type a word: Absolutely | | Type a word: Awesome | | "A" is for "Awesome"