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
Naily [24]
4 years ago
7

Write a function that takes as input an English sentence (a string) and prints the total number of vowels and the total number o

f consonants in the sentence. The function returns nothing. Note that the sentence could have special characters like dots, dashes, and so on.
Computers and Technology
1 answer:
antoniya [11.8K]4 years ago
3 0

Answer:

   public static void vowelCount(String word){

       int vowelCount =0;

       int consonantCount =0;

       int wordLen = word.length();

       //a,e,i,o,u

       for(int i=0; i<word.length(); i++){

           if(word.charAt(i)=='a'||word.charAt(i)=='e'||word.charAt(i)=='i'

                   ||word.charAt(i)=='o'||word.charAt(i)=='u'){

               vowelCount++;

           }

       }

       System.out.println("Number of Vowels: "+vowelCount);

       System.out.println("Number of Consonants: "+ (wordLen-vowelCount));

   }

Explanation:

The method vowelCount is implemented in Java

Receives a string as argument

Uses a for loop to iterate the entire string

Uses an if statement to check for vowels

Substract total vowels from the length of the string to get the consonants

See complete code with a main method below:

import java.util.Scanner;

<em>public class num2 {</em>

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

<em>    Scanner in = new Scanner(System.in);</em>

<em>        System.out.println("Enter a String");</em>

<em>        String word = in.nextLine();</em>

<em>        //Removing all special characters and whitespaces</em>

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

<em>//Calling the Method        </em>

<em>vowelCount(cleanWord);</em>

<em>    }</em>

<em>//The method</em>

<em>    public static void vowelCount(String word){</em>

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

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

<em>        int wordLen = word.length();</em>

<em>        //a,e,i,o,u</em>

<em>        for(int i=0; i<word.length(); i++){</em>

<em>            if(word.charAt(i)=='a'||word.charAt(i)=='e'||word.charAt(i)=='i'</em>

<em>                    ||word.charAt(i)=='o'||word.charAt(i)=='u'){</em>

<em>                vowelCount++;</em>

<em>            }</em>

<em>        }</em>

<em>        System.out.println("Number of Vowels: "+vowelCount);</em>

<em>        System.out.println("Number of Consonants: "+ (wordLen-vowelCount));</em>

<em>    }</em>

<em>}</em>

You might be interested in
When using the protection options in Excel 2016, what does the Protect Workbook function do?
solmaris [256]

Answer:

it saves the workbook in a way that will allow only a select group of people to access it

5 0
3 years ago
Read 2 more answers
In 2-5 sentences, explain how columns can be used and set up to increase the effectiveness of business documents.
nataly862011 [7]

MS word columns help one create a better- looking document when that document has a lot of text. Not only do columns help one organize text in a newspaper kind style of format, but they also are useful for step by step documents like reports and brochures. Just like the old days when the Romans used columns to support the structure of their structure, columns are used to support the structure of our design and structure.

5 0
3 years ago
What are the principles for computer programming?<br> Please add some examples
vaieri [72.5K]
Computer Programming is the process of writing, testing, troubleshooting, debugging and maintaining of a computer program. Good programming practices mix art, craft and engineering discipline.
3 0
4 years ago
If you want to copy data from one cel to another cell that is several rows down in a worksheet, which method should you use?
bogdanovich [222]

copy and paste

so you can keep the data in the current cell and add it to other cells that you want that data in as well

5 0
4 years ago
Write a short essay about the best rotary-wing aircraft ever. It must be a specific aircraft and consist of three paragraphs. In
muminat

Answer:

hi po lalaki ka po

Explanation:

☺☺

7 0
3 years ago
Other questions:
  • Building relationships during your career exploration is called
    9·2 answers
  • Spreadshet formula to add totals​
    12·1 answer
  • If you want to copy a file from one folder to another , what would you do?
    15·1 answer
  • What does NVRAM stand for
    8·2 answers
  • Take the template and complete creation and ordering of the Triangular Matrix. //Complete the following Functions int**fillAry(i
    7·1 answer
  • Matt is a senior developer for Cyber Protect, a company that helps secure management information systems. Matt's new task is to
    8·1 answer
  • Which type of memory helps in reading as well as writing data?
    7·1 answer
  • How do i mark answers brainliest on brainly
    11·2 answers
  • You want to read input from the user to know how many apples they would like
    10·1 answer
  • 4.8 code practice question 1 edhesive
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!