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
To carry computer data over the long haul, wans need to have a(n) ________ in multiple towns and cities.
nika2105 [10]
<span>To carry computer data over the long haul, wan need to have a </span>POP (point of presence) <span>in multiple towns and cities. It is a</span><span>n artificial demarcation point OR interface point between communicating entities</span>


3 0
4 years ago
) Suppose algorithm A takes 10 seconds to handle a data set of 1000 records. Suppose the algorithm A is of complexity O(n2). Ans
Mice21 [21]

Answer:

i) The time taken for 1500 records = 15 seconds.

ii) The time taken for 1500 records = 50 seconds.

Explanation:

A is an O(n) algorithm.

An algorithm with O(n) efficiency is described as a linearly increasing algorithm, this mean that the rate at which the input increases is linear to the time needed to compute that algorithm with n inputs.

From the question, it is given that for 1000 records, the time required is: 10 seconds.

Algorithm time taken is O(n)

Hence,

1) For 1,500 records

=> 10/1000 = x/1500

=> 10x1500/1000 = x

x = 15 seconds

Thus, the time taken for 1500 records = 15 seconds.

2) For 5,000 records

=> 10/1000 = x/5000

=> 10x5000/1000 = x

x = 50 seconds

Thus, the time taken for 1500 records = 50 seconds.

8 0
3 years ago
It is considered good practice to save a presentation before printing it. true false
Ilya [14]
It is true because it is really a good practise to save a presentation before printing it

5 0
3 years ago
Two or more computers connected together is referred to as a(n)
oksian1 [2.3K]
That would be a network my friend. When two or more computers are connected to one another, you have a network.
8 0
3 years ago
A file can be safed with a different file name then it currently has by clicking on save ? in the file tab
Mazyrski [523]

Answer:

Click the File tab. Click Save As. Choose a file location, such as OneDrive or This PC to store your file.

Explanation:

click the File tab. Click Save As. Choose a file location, such as OneDrive or This PC to store your file. In the File name box, enter a new name for the file. In the Save as type list, click the file

5 0
2 years ago
Other questions:
  • Make a java program to enter a two-digit integer and determine if both digits are prime
    6·1 answer
  • Which is the last step in conducting a URL search?
    6·1 answer
  • Suppose there is a class AirConditioner. The class supports the following behaviors: turning the air conditioner on and off. The
    8·1 answer
  • Which of these describes the functionality of a database? Check all of the boxes that apply.
    10·2 answers
  • What are the first two models, e.g. diagrams that affect the entire system, that are built during the CoreProcess to discover an
    5·1 answer
  • In a stream channel what is deposited first?
    7·1 answer
  • This is A C++ PROGRAM BTW!! Define a class named Money that stores a monetary amount. The class should have two private integer
    6·1 answer
  • A vital step in maintaining an operating system is to regularly do what? Replace the hard drive. Organize the computer’s data. R
    11·2 answers
  • The length of the hypotenuse of a right-angled triangle is the square root of the sum of the squares of the other two sides. Wri
    7·1 answer
  • If one of the resistors is turned off (I.e. , a light bulb goes out), what happens to the other resistors (light bulbs) in the c
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!