answer.
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
Umnica [9.8K]
2 years ago
11

consonantCount (s2) Write the function consonantCountthat counts how many times a consonant (either lowercase or uppercase) occu

rs in a string. It takes a string sas input and returnsan integer, the number of consonants in the string. For this question, yand Yare not consonants. Please use a for loop to do the computation. Please do not use a brute force solution (comparing against one consonant at a time): it will not receive credit.
Computers and Technology
1 answer:
Sidana [21]2 years ago
3 0

Answer:

public static int consonantCount(String str){

       int numOfConsonants =0;

       int numOfVowels =0;

       String word = str.toLowerCase();

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

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

                   ||word.charAt(i)=='e'||word.charAt(i)=='u'||word.charAt(i)=='y'){

              numOfVowels++;

           }

       }

       numOfConsonants = (word.length()-numOfVowels);

       return numOfConsonants;

   }

Explanation:

Using Java programming Language

  • Create two variables int numOfConsonants and int numOfVowels To hold the number of consonants and vowels repectively
  • The english vowels for this question includes y or Y
  • Convert the string entered into all lower case letters using java's toLowerCase method
  • Using a for loop count the total number of vowels in the string
  • Subtract the number of vowels in the string from the length of the string to get the number of consonants
  • return the number of consonants
  • Consider a complete program below where a user is prompted to enter a string, the string is stored in a variable, the string is cleaned (Removing all special characters and whitespaces)
  • The method cosonantCount is then called

<em>import java.util.Scanner;</em>

<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 a = in.nextLine();</em>

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

<em>        System.out.println("The number of consonants in the word are "+consonantCount(cleanText));</em>

<em>    }</em>

<em>    public static int consonantCount(String str){</em>

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

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

<em>        String word = str.toLowerCase();</em>

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

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

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

<em>               numOfVowels++;</em>

<em>            }</em>

<em>        }</em>

<em>        numOfConsonants = (word.length()-numOfVowels);</em>

<em>        return numOfConsonants;</em>

<em>    }</em>

<em>}</em>

You might be interested in
Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
Margaret [11]

Answer:

Copying anything may be the computer program or an entertainment file, it is not a good thing as the original developers or the writers are going to feel bad since their hard work is being used by others without letting them know. However, if you are using it for academic purposes, or give them credit in your work, then the original writer will not feel that bad as he is being credited, and hence you can reuse in that case definitely, but always ensure to give the credit to the original writer.

As an example, if a film is copied like many in the past the Directors always feel bad, and they have the reason for feeling bad. The same thing is to technology.

Explanation:

The answer is self explanatory.

8 0
2 years ago
Seneca has just applied conditional formatting and realizes that she has made a mistake. Which action should she take to fix the
erastova [34]

If Seneca has not done anything since the conditional formatting she can undo what her last action was. This is done by either pressing control+Z or by clicking on the undo icon.

If other actions have been done, there are a few more steps that need to be taken in order to clear the formatting. They are:

1. Select the cell or cells whose formatting you want to delete.

2. Display the Home tab of the ribbon.

3. In the Editing group, click Clear | Clear Formats.

8 0
2 years ago
In what year were graphical user interfaces (GUIs) pioneered? 1969 1974 1991 2001
natima [27]
Graphical user interface [GUIs] was pioneered in 1969.
Graphical user interface refers to the use of pointing devices and graphic icons to control a computer. It allows users to interact with the computer hardware 
The development and the refinement of graphical user interface had be ongoing for about fifty years. In the late 1960s, Stanford Research Institute scientists developed the online system, which used a new device called mouse. 
7 0
2 years ago
Read 2 more answers
Select the described workplace culture from the drop-down menu.
Vilka [71]

Answer:

  • Adaptive
  • Consistency-oriented
  • Achievement-based
  • Involvement-oriented

Explanation:

Adaptive Consistency-oriented workplace cultures emphasizes reacting quickly to change.

Consistency-oriented workplace cultures emphasizes everyone being in agreement.

Achievement-based Consistency-oriented workplace cultures emphasizes accomplishing goals.

Involvement-oriented Achievement-based workplace cultures emphasize development of new skills.

7 0
2 years ago
Read 2 more answers
_____ computing refers to a computing environment that is always present, can feel our surroundings, and-based on who we are, wh
tensa zangetsu [6.8K]

Answer:

b. Contextual computing

Explanation:

Contextual computing -

In this method of computing , the hardware and the software collect and examine the data all by itself from the near by areas in order to make it presentable , is known as the method of contextual computing .

It is also known as the context - aware computing .

Hence , from the given information of the question , the correct term from the given options is b. Contextual computing .

4 0
2 years ago
Other questions:
  • The term load is often used to describe opening a page in a ____. Answer
    11·1 answer
  • Which of the following is true about simulation games? A. Simulation games involve competing in a sport against other players. B
    10·2 answers
  • How efficient would a 6-bit code be in asynchronous transmission if it had 1 parity bit, 1 start bit, and 2 stop bits?
    5·1 answer
  • ​identify a text-level element used to mark generic run of text within the document.
    15·1 answer
  • Adrian has decided to create a website to catalog all the books he has in his personal library. He wants to store this informati
    11·2 answers
  • PHP is based on C rather than ______.
    5·1 answer
  • Ken Olson, president of Digital Equipment Corp. in the late 1970's, Thomas J. Watson, chairman of IBM in the early 1940's, and T
    6·1 answer
  • In this exercise we look at memory locality properties of matrix computation. Th e following code is written in C, where element
    9·1 answer
  • 1. What are the first tasks the Team Leader (TL) must perform after arriving at the staging area?
    15·1 answer
  • c Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call FindMax() twice in a
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!