CountVowels specs ** CountVowels Ask the user to enter a string. Print how many different vowels...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
CountVowels specs ** CountVowels Ask the user to enter a string. Print how many different vowels there are in the string (e.g. "aaaee" has 2 different vowels). Ignore case, i.e. 'A' and 'a' are considered to be the same vowel. y' is not considered a vowel. Look at the examples of output below and match them. Make sure you do match the examples below. Example: When the user enters the string: "It's Owl Stretching Time" the program should say that there are 3 different vowels in the string. DO NOT USE LOOPS. Hint You could solve this problem by using a method of String called indexOf indexOf(ch): Returns the index within this string of the first occurrence of the character ch. If ch is not in the string, it returns -1 For example: String foo; foo = "hello"; System.out.println(foo.indexOf('')); prints 2 System.out.println(foo.indexOf('x')); prints -1 Examples % java Count Vowels % java CountVowels enter a string: qqqqqq the string contains no vowels % java Count Vowels enter a string: qqqaaaaaqqaaaaaqq the string contains: 1 vowel % java Count Vowels enter a string: qqqqqqqqqqqqqqqu the string contains: 3 vowels % java CountVowels enter a string: pppppapppp the string contains: 1 vowel % java Count Vowels enter a string: aaeeiioouu the string contains: 5 vowels % • Previous Next 123456780 20E CountVowels.java public class CountVowels { public static void main(String arg []) throws Exception { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); Scanner s=new Scanner(System.in); System.out.print("Enter the string: "); String input-br.readLine(); int c=0; if(input.indexOf('A')>-1 || input.indexOf('a')>−1) { } 9 10 11 { 12 13 } 14 15 16 17 18 19 { 20 21 } 22 23 { 24 25 } 26 27 { 28 29 30 31 C++; if(input.indexOf('E')>-1 || input.indexOf('e')>-1) C++; if(input.indexOf('I')>-1 || input.indexOf('i')>-1) C++; if(input.indexOf('0')>-1 || input.indexOf('0')>-1) C++; if(input.indexOf('U')>-1 || input.indexOf('u')>-1) C++; System.out.println("the string contains:"+ C +"vowels"); 32 33 } 21 CountVowels specs ** CountVowels Ask the user to enter a string. Print how many different vowels there are in the string (e.g. "aaaee" has 2 different vowels). Ignore case, i.e. 'A' and 'a' are considered to be the same vowel. y' is not considered a vowel. Look at the examples of output below and match them. Make sure you do match the examples below. Example: When the user enters the string: "It's Owl Stretching Time" the program should say that there are 3 different vowels in the string. DO NOT USE LOOPS. Hint You could solve this problem by using a method of String called indexOf indexOf(ch): Returns the index within this string of the first occurrence of the character ch. If ch is not in the string, it returns -1 For example: String foo; foo = "hello"; System.out.println(foo.indexOf('')); prints 2 System.out.println(foo.indexOf('x')); prints -1 Examples % java Count Vowels % java CountVowels enter a string: qqqqqq the string contains no vowels % java Count Vowels enter a string: qqqaaaaaqqaaaaaqq the string contains: 1 vowel % java Count Vowels enter a string: qqqqqqqqqqqqqqqu the string contains: 3 vowels % java CountVowels enter a string: pppppapppp the string contains: 1 vowel % java Count Vowels enter a string: aaeeiioouu the string contains: 5 vowels % • Previous Next 123456780 20E CountVowels.java public class CountVowels { public static void main(String arg []) throws Exception { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); Scanner s=new Scanner(System.in); System.out.print("Enter the string: "); String input-br.readLine(); int c=0; if(input.indexOf('A')>-1 || input.indexOf('a')>−1) { } 9 10 11 { 12 13 } 14 15 16 17 18 19 { 20 21 } 22 23 { 24 25 } 26 27 { 28 29 30 31 C++; if(input.indexOf('E')>-1 || input.indexOf('e')>-1) C++; if(input.indexOf('I')>-1 || input.indexOf('i')>-1) C++; if(input.indexOf('0')>-1 || input.indexOf('0')>-1) C++; if(input.indexOf('U')>-1 || input.indexOf('u')>-1) C++; System.out.println("the string contains:"+ C +"vowels"); 32 33 } 21
Expert Answer:
Answer rating: 100% (QA)
Heres the corrected code Java public class CountVowels public static void mainString arg throws Exce... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
In Problems 1158, perform the indicated operation, and write each expression in the standard form a + bi. 3i(-3 + 4i)
-
On January 1, 2017, Magee Corporation started doing business by hiring R. Walker as an employee at an annual salary of $50,000, with an annual salary increment of $10,000. Based on his current age...
-
Mr. O earned an $89,000 salary, and Mrs. O earned a $40,330 salary. The couple had no other income and cant itemize deductions. a. Compute their combined tax if they file separate returns. b. Compute...
-
Which of these statements about energy flow in ecosystems is false? (a) Energy from sunlight enters the biotic world when plants and other photosynthesizers use it to build organic molecules. (b)...
-
Hoover Cole Sunglasses sell for about $ 153 per pair. Suppose the company incurs the following average costs per pair: Direct...
-
How did XYZ Electronics measure the success of its marketing strategy, and what were the key performance indicators (KPIs) it used to assess progress?
-
W&S Partners has just won the January 31, 2026, audit for Cloud 9. As a part of the risk assessment phase for the new audit, the audit team needs to gain an understanding of Cloud 9's structure and...
-
What should the manager do if employees and their supervisors do not agree on what is part of the employees' jobs?
-
CASE: Westminster Company: A System Design Assessment products are marketed through a network of diverse retailers and wholesalers. Trade class as a percent of sales is 37% grocery, 20% drug, 35%...
-
In the context of parallel and concurrent programming paradigms, analyze the role of the "continue" statement in loop parallelization and task scheduling strategies, particularly in scenarios where...
-
Considering the principles of code readability and maintainability, discuss strategies for effectively using lambda expressions to enhance code expressiveness without sacrificing clarity, including...
-
High Deals is an e-commerce company based in Seattle, Washington. In 2020, the company's revenue was $4,300,000 and its cost of goods sold was $3,200,000. Assume 52 weeks and 365 days per year....
-
Wayne and Carol have been married for 6 0 years. At Carol s passing ( and Wayne surviving ) all of the assets, worth $ 4 0 Million, are either titled as Joint Tenancy with Rights of Survivorship or...
-
Q1) Define: diffraction interference , resolving time, Dispersion 02) The diffraction of light depends on the wave nature of light or the particle nature of light. 03) What is the main difference...
-
-x/2 x/4 If A = -x/2 and A-1 =6 then x equals
-
Two arrays in which each element in one array is associated with the element in the same relative position are ____________. a. Cohesive b. Parallel c. Hidden d. Perpendicular
-
Your downloadable files for Chapter 11 include DEBUG11-01.txt, DEBUG11-02.txt, and DEBUG11-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with...
-
As this chaptermentions, some programming languages require that named constants are assigned a value when they are declared; other languages allow a constant's value to be assigned later in a...
-
Starfleet Corporation has one temporary difference at the end of 2014 that will reverse and cause taxable amounts of $55,000 in 2015, $60,000 in 2016, and $75,000 in 2017. Starfleets pretax financial...
-
At December 31, 2015, Suffolk Corporation had an estimated warranty liability of 105,000 for accounting purposes and 0 for tax purposes. (The warranty costs are not deductible until paid.) The...
-
State whether each of the following events will result in a movement along General Motors (GMs) demand curve for labor in their U.S. automobile factories or whether it will cause its demand curve for...
Study smarter with the SolutionInn App