Fangflora3
11.03.2020 •
Computers and Technology
Write a function called count_vowels that accepts a string argument that represents a word and returns the number of vowels that are in the word. The vowels are A, E, I, O, and U (ignore the 'sometimes Y' rule). Count both uppercase and lowercase vowels.
Solved
Show answers
More tips
- G Goods and services What Are the Most Popular Services?...
- P Philosophy How did the concept of module arise in computer science?...
- D Dating, Love, Relationships Why Should the Man be Active and the Woman Passive during Foreplay?...
- S Society and Politics Выборы: Смысл, Значение и Отражение...
- B Business and Finance How to Get Your Money Back When Lending? Top 7 Ways...
- F Family and Home Do Lullabies Help Babies Sleep or Is it Just a Myth?...
- F Family and Home Why Does God Punish Us Constantly and How Can We Fix It?...
- D Dating, Love, Relationships Why do we feel shame?...
- S Society and Politics How Could Nobody Know About the Dead Mountaineers?...
- O Other How to Accidentally Get a Rare Coin with Your Change and How to Know Its Value?...
Answers on questions: Computers and Technology
- C Computers and Technology Which sentence best describes the entire energy career cluster...
- C Computers and Technology Which of the following is true about scalability? i. weak scaling is easier to achieve than strong scaling due to amdahl’s law. ii. amount of communication among processors usually...
- C Computers and Technology 1. i) pick a parentheses expression. explain and show how parentheses matching works. also write the algorithm. ii) draw an expression tree for +1)*3)/((9-5)+*(7-4))+6))...
- C Computers and Technology Name one advantage of modular switches over fixed-configuration switches. group of answer choices a. lower forwarding rates b. need for more power outlets c. expansion in number of...
- C Computers and Technology If we compare the solution from an analytical model with that from a computer simulation we will typically find them to be exactly the same. true or false...
- C Computers and Technology Suppose you have an int variable called number. what java expression produces the second-to-last digit of the number (the 10s place)? what expression produces the third-to-last digit...
- C Computers and Technology Peter extracts the sids list from windows 2000 server machine using the hacking tool sidextractor . here is the output of the sids: from the above list identify the user account with...
- C Computers and Technology Compare and contrast Android and IOS operating systems in terms of a variety of functions such as Management of user accounts, Loading and running of applications, Memory management,...
- E English Wuthering heights shares literary elements with frankenstein. to which literary genre do the two novels belong? a. horror b. gothic c. fantasy d. legend...
- M Mathematics Find the value of x. a. 4 square root of 3 b. 8 square root of 3 c. 8 d. 16 i feel like it may be c but my gut says ask for some ....
Ответ:
public static int count_vowels(String str){
String word = str.replaceAll("[^a-zA-Z0-9]", "");
String text = word.toUpperCase();
int lenOfString = text.length();
int count =0;
for(int i =0; i<lenOfString; i++){
if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'
||text.charAt(i)=='O'||text.charAt(i)=='U'){
count++;
}
}
return count;
}
Explanation:
This has been implemented using Java programming language.
Firstly, white spaces, special characters and punctions are removed from the string uisng the replaceAll() method
The string is converted to all upper cases
a for loop is used to count the number of vowels and store to a variable count
In the main method a call to count_vowels is done
public class num1 {
public static void main(String[] args) {
String name = "David %$ !. gjak";
System.out.println("The number of vowels in "+name+ " are "+count_vowels(name));
}
public static int count_vowels(String str){
String word = str.replaceAll("[^a-zA-Z0-9]", "");
String text = word.toUpperCase();
int lenOfString = text.length();
int count =0;
for(int i =0; i<lenOfString; i++){
if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'
||text.charAt(i)=='O'||text.charAt(i)=='U'){
count++;
}
}
return count;
}
}
The complete program with a Main method is given below
Ответ: