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
Select the correct answer.
jenyasd209 [6]
I think it is D
Hope my answer help you?
5 0
3 years ago
‘‘Anyone in the developed world can publish anything anytime, and the instant it is published, it is globally available and read
taurus [48]
The internet made huge changes to the way news and information were shared. While it was faster to use newspapers or magazines to spread information than it was to simply tell people, they were still very inefficient compared to today's technology. With the internet today, anyone can come online and learn about what's happening in the far corners of the world. Take your question, for instance. If there was no internet, you might have to post a notice somewhere, which could take days to answer. However, since you were able to post this on the internet, I'm able to answer it within five minutes of it being posted.
8 0
3 years ago
Apple's macos and microsoft windows are examples of ________ software. select one:
Soloha48 [4]
D.operating system
mac is an unix based os
3 0
3 years ago
When a program lets the user know that an invalid menu choice has been made, this is an example of?
kolezko [41]

The question has the multiple choices below

A) Input validation
B) output correction
C) compiler criticism
D) output validation

The answer is (A) Input validation

Also known as data validation, it is the correct and proper testing of any input supplied by an application or a user. It prevents wrongly formed data from entering the system. Applications should be able to check and validate every input entered into the system since it is hard to detect a malicious user trying to gain entry into software.










5 0
3 years ago
When you are creating a game you plan to sell online and you need to implement art:
Lilit [14]

Answer:

you can download images that the creator has given permission to use freely.

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • What seems to be the prevailing opinion about enterprise clouds?
    8·2 answers
  • I need help with this assignment
    10·1 answer
  • Information security is defined as practice of preventing unauthorized access, use, disclosure, disruption, modification, or ___
    6·1 answer
  • Establishing responsibilities, planning to best support the organization, acquiring validity, ensuring performance, conformity w
    12·1 answer
  • DRIVER ED
    13·2 answers
  • A short story, but i remember in 1nd - 5th grade at my elementary school here is the list from first to last for being cool at s
    9·2 answers
  • . 。 • ゚ 。 .
    10·2 answers
  • You’ve been given a new cell phone with a 2 gigabyte data plan. You plan to use your phone for text messages, images, video, and
    13·1 answer
  • Information technology student Roberta has been assigned a project on how to detect unwanted outgoing attacks. Which step is par
    12·1 answer
  • which of these devices has 3000-A fuses that provide fault protection for the 4000-a, 480/277-V, 3-phase bus that feeds seven ci
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!