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]
3 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]3 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
Which one is not an operating system?1.mac 2.Microsoft office3.Iso.3.Android
quester [9]
It's either microsoft or office. Based on research I would say office.

I really hope this helps you! :-)
6 0
3 years ago
Which commas is used to combine two or more cells together into one cell
AURORKA [14]
The command is Merge & Center
This command could be easily found in the toolbar of your excel.
If you execute this command in two different cells, those cells will be merged into one larger cell and the content in that cells will be placed exactly in the middle of the combined cell (measures according to combined cells' length)
5 0
3 years ago
What is an IF statement used for?
kiruha [24]

The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria. The IF statement executes one set of code if a specified condition is met (TRUE) or another set of code evaluates to FALSE.

8 0
3 years ago
Edhesive assignment 7 calendar
ikadub [295]

Answer:

def leap_year(y):

 if y % 4 == 0:

     return 1

 else:

     return 0

def number_of_days(m,y):

 if m == 2:

     return 28 + leap_year(y)

 elif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m ==10 or m == 12:

     return 31

 elif m == 4 or m == 6 or m == 9 or m == 11:

     return 30

def days(m,d):

 if m == 1:

     return 0 + d

 if m == 2:

     return 31 + d

 if m == 3:

     return 59 + d

 if m == 4:

     return 90 + d

 if m == 5:

     return 120 + d

 if m == 6:

     return 151 + d

 if m == 7:

     return 181 + d

 if m == 8:

     return 212 + d

 if m == 9:

     return 243 + d

 if m == 10:

     return 273 + d

 if m == 11:

     return 304 + d

 if m == 12:

     return 334 + d

def days_left(d,m,y):

 if days(m,d) <= 60:

     return 365 - days(m,d) + leap_year(y)

 else:

     return 365 - days(m,d)

print("Please enter a date")

day=int(input("Day: "))

month=int(input("Month: "))

year=int(input("Year: "))

choice=int(input("Menu:\n1) Calculate the number of days in the given month.\n2) Calculate the number of days left in the given year.\n"))

if choice == 1:

 print(number_of_days(month, year))

if choice == 2:

 print(days_left(day,month,year))

Explanation:

Hoped this helped

5 0
3 years ago
What is output? public class MathRecursive { public static void myMathFunction(int a, int r, int counter) { int val; val = a*r;
ycow [4]

Answer:

The output of the program is:

2 4 8 16 32 64 End

Explanation:

See attachment for proper presentation of the program

The program uses recursion to determine its operations and outputs.

The function is defined as: myMathFunction(int a, int r, int counter)

It initially gets the following as its input from the main method

a= 1; r = 2; counter = 0

Its operation goes thus:

val = a*r; 1 * 2 = 2

Print val; Prints 2

if (counter > 4) { System.out.print("End"); } : Not true

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 2; r = 2; counter = 1

val = a*r; 2 * 2 = 4

Print val; Prints 4

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 4; r = 2; counter = 2

val = a*r; 4 * 2 = 8

Print val; Prints 8

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 8; r = 2; counter = 3

val = a*r; 8 * 2 = 16

Print val; Prints 16

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 16; r = 2; counter = 4

val = a*r; 16 * 2 = 32

Print val; Prints 32

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 32; r = 2; counter = 5

val = a*r; 32 * 2 = 64

Print val; Prints 64

if (counter > 4) { System.out.print("End"); } : True

<em>This prints "End"</em>

So; the output of the program is:

2 4 8 16 32 64 End

3 0
3 years ago
Other questions:
  • Why should spain go to Africa ​
    15·1 answer
  • Tom wants a way to automatically create ads and simplify campaign management, using his resources and Google's machine learning
    12·1 answer
  • Answer the following questions which are based on the study "Patients' Engagement with Sweet Talk." Submit your answers to the e
    9·1 answer
  • PLEASE HELPPPPPPP
    15·1 answer
  • For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
    12·1 answer
  • What type of backlighting receives dc power directly from a motherboard and doesn't use an inverter?
    11·1 answer
  • What is DMTS. Explain it​
    10·2 answers
  • Why would an end-user not generally buy a server? Explain your answer by referring to the typical role that servers perform. ​
    12·1 answer
  • Why do designers of smartphones hide computer processing details from
    14·2 answers
  • What do you mean by computer ethics?​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!