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
Liono4ka [1.6K]
3 years ago
9

Write a function called count_vowels that accepts a string argument that represents a word and returns the number of vowels that

are in the word. The vowels are A, E, I, O, and U (ignore the 'sometimes Y' rule). Count both uppercase and lowercase vowels.
Computers and Technology
1 answer:
stellarik [79]3 years ago
3 0

Answer:

public static int count_vowels(String str){

       String word = str.replaceAll("[^a-zA-Z0-9]", "");

       String text = word.toUpperCase();

       int lenOfString = text.length();

       int count =0;

       for(int i =0; i<lenOfString; i++){

           if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'

                   ||text.charAt(i)=='O'||text.charAt(i)=='U'){

               count++;

           }

       }

       return count;

   }

Explanation:

This has been implemented using Java programming language.

Firstly, white spaces, special characters and punctions are removed from the string uisng the replaceAll() method

The string is converted to all upper cases

a for loop is used to count the number of vowels and store to a variable count

In the main method a call to count_vowels is done

<em>public class num1 {</em>

<em>    public static void main(String[] args) {</em>

<em>        String name = "David %$ !. gjak";</em>

<em>        System.out.println("The number of vowels in "+name+ " are "+count_vowels(name));</em>

<em>    }</em>

<em>    public static int count_vowels(String str){</em>

<em>        String word = str.replaceAll("[^a-zA-Z0-9]", "");</em>

<em>        String text = word.toUpperCase();</em>

<em>        int lenOfString = text.length();</em>

<em>        int count =0;</em>

<em>        for(int i =0; i<lenOfString; i++){</em>

<em>            if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'</em>

<em>                    ||text.charAt(i)=='O'||text.charAt(i)=='U'){</em>

<em>                count++;</em>

<em>            }</em>

<em>        }</em>

<em>        return count;</em>

<em>    }</em>

<em>}</em>

<em />

The complete program with a Main method is given below

You might be interested in
Hey guys... I know this is homework question but I need to see other opinions.. Should I get the Apple iPad Air or the Apple iPa
RSB [31]
You should get the 8th generation
6 0
3 years ago
Ip ____ is the falsification of the source ip address in a packet's header so that it appears to have come from a trusted or leg
tensa zangetsu [6.8K]
<span>IP spoofing the falsification of the source ip address in a packet's header so that it appears to have come from a trusted or legitimate sender.</span>
5 0
3 years ago
Which destination ipv4 address does a dhcpv4 client use to send the initial dhcp discover packet when the client is looking for
Dima020 [189]
<span>A DHCPv4 client use the broadcast IP address to send the initial DHCP discover packet when the client is looking for a DHCP server. </span><span>
A workstation will send a DHCPDISCOVER message to start the process of obtaining a valid IP address. The client  does not know the addresses of DHCP servers, and that's why it sends the message via broadcast, with destination addresses of FF-FF-FF-FF-FF-FF and 255.255.255.255.</span>
5 0
4 years ago
Was the big blue button thing a good decision or bad?<br> *I think it was a bad idea.
Gala2k [10]

sorry i just got banned so delete this answer plz i was banned and i wanted to see if they unbanned me

8 0
4 years ago
Read 2 more answers
With working from home now becoming a norm what is an effective network for an organization to secure its internal resources acc
Umnica [9.8K]

Answer:

Always encrypt data never store anything in plain text someone could use wireshark to pull out a data packet and if the data is not encrypted, expect things to happen.

4 0
3 years ago
Other questions:
  • Which are examples of intrapersonal goals? Check all that apply. Lea plans to finish her next project before the due date. Erick
    12·2 answers
  • You will use the _____
    15·2 answers
  • The inherent portability of which medium, gives it an advantage over other types of media that require an individual’s full atte
    10·1 answer
  • Select the three early tools that were prototypes of modern farming tools used for harvesting crops.
    14·1 answer
  • In a typical e-mail address the host is
    14·1 answer
  • A third party intercepting a packet and downloading its information before it is sent onward toward its destination is called
    10·1 answer
  • Which of the following is a Microsoft solution
    11·1 answer
  • Linux distributions automatically come with a native software firewall.TrueFalse
    13·1 answer
  • Identify the type of error described
    6·1 answer
  • When Jimmy Fallon is outside the White House, his persona is mostly O A. humble O B. stern O c. gloomy O D. wild​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!