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
tino4ka555 [31]
4 years ago
6

Write a program with functions that accepts a string as an argument and returns the number of vowels that the string contains. T

he application should have another function that accepts a string as an argument and return the number of consonants that the string contains. The application should let the user enter a string and should display the number of vowels and the number of consonants it contains.
Computers and Technology
1 answer:
suter [353]4 years ago
7 0

Answer:

import java.util.Scanner;

public class num11 {

   public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

       System.out.println("Enter a word or phrase");

       String word = in.nextLine();

       //Calling the methods

       System.out.println("Total vowels in "+word+" are "+numVowels(word));

       System.out.println("Total consonants in "+word+" are "+numConsonants(word));

   }

   public static int numVowels(String word){

       //Remove spaces and convert to lowercase

       //Assume that only correct character a-z are entered

       String newWord = word.toLowerCase().replaceAll(" ","");

       int vowelCount = 0;

       for(int i = 0; i <= newWord.length()-1; i++){

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

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

               vowelCount++;

           }

       }

       return vowelCount;

   }

   public static int numConsonants(String word){

       //Remove spaces and convert to lowercase

       //Assume that only correct character a-z are entered

       String newWord = word.toLowerCase().replaceAll(" ","");

       int consonantCount = 0;

       //Substract total vowels from the length of the word to get the consonants

       consonantCount = newWord.length()-numVowels(word);

       return consonantCount;

   }

}

Explanation:

  • Create two methods vowelCount() and consonantCount() both accepts a string parameter and returns an int
  • vowelCount() Uses a for loop to count the occurrence of the vowels (a,e,i,o,u) in the string and returns the count.
  • consonantCount calls vowelCount and subtracts the vowelCount from the string length
  • In the main Method the user is prompted to enter a string
  • The two methods are called to return the number of vowels and consonants
  • Observe also that it is assumed that user entered only strings containing the character a-Z.
  • Observe also that the string is converted to all lower cases and whitespaces removed.
You might be interested in
PLEASE PLEASE PLEASE PLEASE HELP ASAP!!!!! I PROMISE I WILL GIVE YOU A BRAINLIEST FOR THE CORRECT ANSWER PLEASE HELP!!
inysia [295]
The answer will be C

As she is about to leave the position, in account of professionalism, she should NOT do any unnecessary harm to the current company, and  she should notify the company for necessary description before leaving. 
5 0
3 years ago
Read 2 more answers
You are part of the team to implement new software at XYZ Inc. The employees at XYZ Inc. trust the results of the old software p
sasho [114]

Answer:

Option (D) i.e., Parallel start up is correct option to the following question.

Explanation:

Parallel startup is also an application or software or a way of using the application of the other Operating System in others just like that the following XYZ inc. has trust on older platform but their system give them cautions for update then they use parallel set up by which they also use old software, as well as they, use the Mac's software in Windows. This strategy provides both the option of usage.

8 0
3 years ago
Estoy haciendo codificación en este momento es tan confuso y no estar en la escuela es más difícil
Katarina [22]

Answer:

Misma

Explanation:

6 0
3 years ago
Read 2 more answers
HELP!!! What would var d=?
sergiy2304 [10]

Answer:

51015

Explanation:

Var b is a string, and it'll treat addition like <em>string concatenation </em>(aka just adding a message.) Since it's concatenation, it'll then turn the numbers/integers into strings.

This kind of behavior might be different depending on the language, though. Some languages might not allow this. (For example, C and C++)

7 0
3 years ago
Laura is confused with the spelling of the word pronunciation. She types the word as pronounciation throughout a document. Which
Ivan

Not really is she wants the words that she's typing down sometimes it's not necessary to leave it to the auto correct It can always be bad when re-reading it again.

5 0
3 years ago
Other questions:
  • What is a major plastics engineering project that is going on right now in Arizona?
    9·1 answer
  • The Internet may best be compared to a/an
    8·1 answer
  • 9. What is composition? Why is composition important?
    11·1 answer
  • Describe the differences between program development and program execution, including the installed software required for develo
    5·1 answer
  • Which of these programmers creates the core game engine?
    5·2 answers
  • A process at Host C receiving two incoming UDP segments from two different hosts will know that they originated from two differe
    14·2 answers
  • Help a brotha out..................
    10·1 answer
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
  • Does any of yall play rob lox?
    5·2 answers
  • Question 2 of 10
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!