1. Prompt the user for a String. (Note: The user input String may contain spaces)2. Print the number of vowels and consonants in the String. The count displayed mustaccount for all the vowels and consonants in the String regardless of case (upper orlower case). You must use a loop in your solutionHint: charAt (index) and length ) method for the String, toUpperCase (ch) (ortoLowerCase (ch) ), isLetter (ch) method for the Character is helpful for thisassignment3. The output from the program must be enclosed in quotes as shown below in the samplerun of the programTwo Sample Run:Enter a string: JAcgaeIOU 123 YRE!The number oT VOWels 15"The number of consonants is 5"Enter a string: 12345 67890The number oT VOwels 15"The number of consonants is Q"

Question
Asked Apr 11, 2019
26 views

Write a program in Eclipse that prompts the user to enter a string and displays the number of vowels and consonants in the string. Assume letters A, E, I, O, U (or a, e, i, o, u) as the vowels.

1. Prompt the user for a String. (Note: The user input String may contain spaces)
2. Print the number of vowels and consonants in the String. The count displayed must
account for all the vowels and consonants in the String regardless of case (upper or
lower case). You must use a loop in your solution
Hint: charAt (index) and length ) method for the String, toUpperCase (ch) (or
toLowerCase (ch) ), isLetter (ch) method for the Character is helpful for this
assignment
3. The output from the program must be enclosed in quotes as shown below in the sample
run of the program
Two Sample Run:
Enter a string: JAcgaeIOU 123 YRE!
The number oT VOWels 15
"The number of consonants is 5"
Enter a string: 12345 67890
The number oT VOwels 15
"The number of consonants is Q"
help_outline

Image Transcriptionclose

1. Prompt the user for a String. (Note: The user input String may contain spaces) 2. Print the number of vowels and consonants in the String. The count displayed must account for all the vowels and consonants in the String regardless of case (upper or lower case). You must use a loop in your solution Hint: charAt (index) and length ) method for the String, toUpperCase (ch) (or toLowerCase (ch) ), isLetter (ch) method for the Character is helpful for this assignment 3. The output from the program must be enclosed in quotes as shown below in the sample run of the program Two Sample Run: Enter a string: JAcgaeIOU 123 YRE! The number oT VOWels 15 "The number of consonants is 5" Enter a string: 12345 67890 The number oT VOwels 15 "The number of consonants is Q"

fullscreen
check_circle

Expert Answer

Step 1

Solution:

Given data,

 

The java code gets the input string from user and display the number of vowels and consonants.

The program has the following algorithm:

  • Create a class Sample.
  • Define the main() method,
    • Create an object for Scanner class.
    • Declare the required variables.
    • Convert the string to upper case and remove leading and trailing spaces.
    • The for Loop executes until length of string. If yes,
      • Check whether character is vowels. If yes, increment the vowels.
      • Otherwise, check whether the character is consonants. If yes, increment the consonants.
  • Display the count of vowels and consonants.
Step 2

Screenshot of program:

fullscreen
Step 3
fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: getRandomLib.h: // This library provides a few helpful functions to return random values// * getRand...

A: Program Instructions:Include the necessary header files.Print hello message and as for a response.De...

question_answer

Q: How do I convert a number to octal without using modulus, multiplication, and division. Also, I can'...

A: To convert an integer number to octal without using multiplication, division and modulus or any inbu...

question_answer

Q: Visual Basic. Given two variables, isEmpty of type boolean, indicating whether a class roster is emp...

A: We have to check two conditions:-1) class roster is not empty 2) The class has more than two credits...

question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz =2; y = z + x;...

A: Call by reference The arguments passed to a function will copy the address of an argument into the f...

question_answer

Q: C++ my programming lab 11.7: Customer AccountsWrite a program that uses a structure to store the fol...

A: Solution:Given data,The C++ code use 20 structures to get the user data, change account information,...

question_answer

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: SELECT Movie_Tiltle, Movie_Year, Price_Description, Rental_Fee FROM Movies WHERE Categories = ‘famil...

question_answer

Q: Draw a full-adder using only NAND gates.

A: The full adder circuit with NAND gates is shown below.  It is a simple 1 bit adder.

question_answer

Q: Eliminate all λ-productions from S → AaB|aaB, A → λ, B → bbA|λ.

A: A procedure of removing all λ productions is as follows:

question_answer

Q: This table is in 1NF. What does the table look like in 3NF? This is about Normalization.

A: First to make the table clears 3NF we need to understand what is Normal form.* Basically normal form...