Question: Write a program in Java to count the words that end in vowels in given sentences: 1. Prompt the user for one string: userStr. 2.
Write a program in Java to count the words that end in vowels in given sentences:
1. Prompt the user for one string: userStr.
2. Print the number of words ending in vowels.
-A vowel is at the end of a word if there is not an alphabetic letter immediately following it.
-The method Character.isLetter() tests if a character is an alphabetic letter (A-Z, a-z). E.g. Character.isLetter('a') is true and Character.isLetter('.') is false.
-See the sample output for examples.
3. Convert the String userStr to an array of characters called userStrArray.
-This step is just one line of code:
-char[] userStrArray = userStr.toCharArray();
4. Repeat step 2, using the character array userStrArray instead of the String userStr, to count the number of words (in the array) ending in vowels.
-It will be the same number of words as the first one.
-Do not use userStr in step 4. Use only userStrArray.
-The goal is to practice using array syntax.
5. Ask the user for another string and, unless the string is "exit", repeat steps 2, 3, 4, 5.
-Steps 1, 2, 3, 4, 5 must execute at least once, even if the user enters "exit" for the first string.
-Only start checking for "exit" when the user enters the second string (and subsequent strings).
6. When the user enters "exit", display a message stating the total number of words ending in vowels (in all sentences combined).
The goals of this assignment are:
To compare the syntax for traversing a string to the syntax for traversing an array in Java.
To practice using loops, if statements, and switch statements.
To write clean, structured code, with easy-to-follow logic.
Sample output for clarification.

MM4MThe number of words in userStr ending in vowels is: 5 MM MThe number of words in userStrArray ending in vowels is: 5 MM&M 4MEnter a sentence (to stop, type exit):Show me the money! MM4MThe number of words in userStr ending in vowels is: 2 MM4MThe number of words in userStrArray ending in vowels is: 2 MEnter a sentence (to stop, type exit): La-dee-da, LA-DEE-DA. MM4MThe number of words in userStx ending in vowels is: 6 MM& MThe number of words in userStrArray ending in vowels is: 6 MM&M 4)Enter a sentence (to stop, type exit): exit MM4MThe total number of words ending in vowels is: 13 MM4MBye! MM&M MMvM--i GRASP: operation complete
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
