1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mr Goodwill [35]
4 years ago
4

Assume letters A, E, I, O, and U as the vowels. Write a program that prompts the user to enter a string and displays the number

of vowels and consonants in the string.
Computers and Technology
1 answer:
alexandr402 [8]4 years ago
5 0

Answer:

The java program is as follows.

import java.util.Scanner;

import java.lang.*;

public class Main

{

   // string array to hold vowels

   static String[] vowels = {"A", "E", "I", "O", "U"};

   

   // variables declared

   static String word;

   static int vowel_count = 0;

   static int consonant_count = 0;

   static String ch;

   static int len;

   

   public static void main(String[] args) {

   

   Scanner sc = new Scanner(System.in);

   

   // user asked to enter a string

   System.out.print("Enter any string consisting of vowels and consonants: ");

   word = sc.nextLine();

   

   // length of string stored in a variable

   len = word.length();

   

   // enhanced for loop used

   for(String v : vowels)

   {

   for(int n=0; n<len; n++)

   {

       // each character in user entered string is tested

       ch = word.substring(n,n+1);

       

       if(ch.equalsIgnoreCase(v))

           vowel_count = vowel_count + 1;

   }

   }

   

   // length of word minus number of vowels give the consonant count

   consonant_count = len - vowel_count;

   

   // number of vowels and consonants displayed

   System.out.println("The string " + word + " has " + vowel_count + " vowels and " + consonant_count + " consonants.");

   

 }

}

OUTPUT

Enter any string consisting of vowels and consonants: TESTING

The string TESTING has 2 vowels and 5 consonants.

Explanation:

1. The program has string variables to enable the usage of string functions.

2. The integer variables are declared to hold the count of vowels, the count of consonants and the length of the user entered string.

3. A string array is declared and initialized with vowels.

4. The string functions are used to compute length of the string, substring yields each character in the user inputted string.

5. Each character in the input string is compared with each of the vowels.

6. Outer enhanced for loop executes on the array holding vowels. Inner for loop executes for each character in the user input string and compares each character with each vowel from the outer enhanced for loop.

7. The program works irrespective of the case of the characters both in the array and in the user entered string.

You might be interested in
Are the blank space around the edges of the page
Law Incorporation [45]

Answer:

The blank space around the edges of a sheet of paper — as with the page of a book — that surrounds the text is called the margin.

8 0
3 years ago
Consider a relation about people in the United States, including their name, Social Security number, street address, city, state
andreyandreev [35.5K]

Answer:

For constructing relational schema, consider the relation as:

Data Attributes for USPeople: name, Social Security number (SSN), street address, city, state,

ZIP code, area code, phone number

1. Functional Dependency (FD):

A functional dependency (FD) is a relationship between the primary key and non-key attributes of  the relation. For finding FD, we need to know about the primary key (PK) which should be unique.

Social Security number (SSN) is the only attribute that holds unique value for relation. R, attribute for any relation Y is functionally dependent on attribute X (usually the PK), if for every  valid instance of X, that value of X uniquely determines the value of Y.

Social Security number (PK) ->;name, street address, city, state, ZIP code, area code, phone  number

2. keys for the relation

Primary key = Social Security Number (PK)

Foreign key = Area code

In the normalization process, we can separate address table (street address, city, state, ZIP  code, area code)

Can an area code straddle two states?

Yes, it can straddle between two states; it might be in cities/regions that “lie” across two states.  For example, Kansas City is in Missouri and Kansas. A lot of people share the same area code.

Can a ZIP code straddle two area codes?

Yes, it can straddle between two states; it might be in cities/regions that “lie” across two states.

Can same Social Security number is allotted to two people?

NO, everyone has a unique SSN number.

Can peoples living together have the same address or phone number?

Yes, people living in the same house share addresses or phone numbers.

4 0
3 years ago
An engineer plans to connect three switches (SW1, SW2, and SW3) in a lab. Before connecting the switches, he starts by configuri
g100num [7]

Answer:

c. All use SW3's database because SW3 has the highest revision number.

Explanation:

In this particular configuration, the three switches will definitely be connected to one another by the presence of some path with the specific trunks. As a result, the database with the most revision number will ultimately win. The process of the STP election does not have any influence on the selection of the VTP.

4 0
3 years ago
The top element in the hierarchy is the html element , which contains all of the other elements within a Hypertext Markup Langua
Anna [14]

the answer is true

The top element in the hierarchy is the html element

6 0
4 years ago
An example of a target group might be people who:
Pie
C. They have something in common: they don't have access to social media.
7 0
3 years ago
Read 2 more answers
Other questions:
  • What are the four basic operating principles of the information processing cycle?
    7·2 answers
  • What happens when two computers use the same IP address?
    6·1 answer
  • Linda is training to become a certified network design expert and consultant. While researching about the process of cellular ra
    12·1 answer
  • Tina has made a database table in access containing field name class roll number and contact number she has set primary key for
    5·1 answer
  • Which of the following is a correct statement about writing down passwords on a ""cheat sheet?""
    7·1 answer
  • Why now days 3D images are used in cartoons? What are the drawbacks of 2D image?
    14·2 answers
  • What is the best free website to learn phyton programming
    5·1 answer
  • ......... mi2hej<br><br>ejid8eo19o1b2bxhxjxjdnneejk2929nr
    5·2 answers
  • What is the purpose the wait block?
    10·1 answer
  • PYTHON --- Toll roads have different fees based on the time of day and on weekends. Write a function calc_toll() that has three
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!