Using an approach similar to that in Worked Example 19.1, find all words with exactly one vowel
Question:
Using an approach similar to that in Worked Example 19.1, find all words with exactly one vowel (which might be repeated). What is the longest one? How many such words exist for each length?
Data from worked example 19.1.
Transcribed Image Text:
WORKED EXAMPLE 19.1 Word Propertles It is fun to find words with interesting properties. To see how streams make this easy, locate the code for Worked Example 19.1 in the companion code for this book. Problem Statement The French word oiseau has five distinct vowels, which is pretty nifty. Are there English words like that? Just a few or a lot? Which words are the shortest and longest among them? Step 1 Get the data. Step 2 Make a stream. compose DILA electric masterpiece ther imagi vilg Step 3 Transform the stream. 7zle iStock.com/tigermad. try (Stream- lines = Files. lines (Paths.get("words.txt"))) { every lopr kno In this case, we need a list of English words. The companion code for this book contains a copy of the words.txt file that is available on computers with a Unix-based operating system. bove In this case, it is very easy to get a stream of words because the input file has one word per line. Simply call balar First, the input contains many words ending with's, such as Alice's. We don't want them: try (Stream- lines = Files. lines (Paths.get("words.txt"))) { Stream words = lines.filter(w -> !w.endsWith("'s")); return word.toLowerCase().codePoints() // A stream of code points filter (c => c == 'a' || c= 'e' || c= '1' || c='0' || c == 'u') .distinct() // The distinct vowels in word .count() == 5; } And we only want words that have all five vowels. This is complex enough that we should write a separate method public static boolean has Five Vowels (String word) This method needs to check whether the word contains all five vowels. As an aside, this too can be done with streams:
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (QA)
Answered By
ATUL GAUTAM
• Year 2018, Class 10 from Ryan International School - secured 94.2%
• Year 2020, Class 12 (Commerce + maths) from Ryan International School - secured 91.6%
• Bachelor of Commerce Pursuing from MJP Rohilkhand University (Swami Shukdevanand College) - secured
1St division (1st & 2nd year)
Current year – 3rd year
• CA Pursuing from Institute of Chartered Accountant of India (ICAI) - secured Foundation – 238/400
Inter – Pursuing
• Expert user of MS DOS and MS Office (Word, Excel, Power Point)
• 1 year of teaching experience in offline mode in the field of accounts and maths to ca foundation students.
• Currently working in different online platform as Q/A Expert.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Java Programming questions
-
Using an approach similar to that in Worked Example 19.1, find all words with length of at least ten in which no letter is repeated. What is the longest one? How many such words exist for each...
-
Worked Example 19.1 showed you how to find all words with five distinct vowels (which might occur more than once). Using a similar approach, find all words in which each vowel occurs exactly once....
-
In Example 3 we showed that an appropriate choice of basis could greatly simplify the computation of the values of a sequence of the form Av, A2v, A3v, ( ( ( ( Exercises 1 and 2 require an approach...
-
A 50 coaxial cable is connected to an 80 resistive load and a dc source with zero internal resistance. Calculate the voltage reflection coefficients at the source and at the load.
-
An air-conditioning system operating on the reversed Carnot cycle is required to remove heat from the house at a rate of 32 kJ/s to maintain its temperature constant at 20C. If the temperature of the...
-
Where are all Java methods defined?
-
Consider two alternatives, each of which will accomplish the same EPA-mandated pollution control. Using an incremental IRR analysis, determine the preferred alternative assuming MARR is 20...
-
Garcia Home Improvement Company installs replacement siding, windows, and louvered glass doors for single-family homes and condominium complexes in northern New Jersey and southern New York. The...
-
Differentiate entity wide controls from transaction controls. Identify at least 3 types of entity wide controls and 3 types of transaction controls. Then, provide an example for each type of control...
-
The G. Saussy Manufacturing company is putting out four new electronic components. Each of Saussy's four plants has the capacity to add one more product to its current line of electronic parts. The...
-
Perhaps the reason that so many movie titles start with the letter A is that their first word is A or An? Count how many movies in the data set of Worked Example 19.2 start with these words. Data...
-
Produce an infinite stream that contains the factorials 1!, 2!, 3!, and so on. Hint: First produce a stream containing arrays [1, 1!], [2, 2!], [3, 3!], and so on. Use BigInteger values for the...
-
To become more skilled at interpreting meanings associated with nonverbal communication. INSTRUCTIONS Assume your boss exhibits each of the four behaviors listed below over the course of a month....
-
What happens to the value of a perpetuity when interest rates increase or decrease?
-
What are the advantages and disadvantages of preferred stock financing?
-
What are the advantages and disadvantages of the holding company form of organization?
-
What is the major difference between fee-for-service reimbursement and capitation?
-
What is a perpetuity?
-
For a firm that you know well, give an example WT Strategy, showing how an internal weakness can be matched with an external threat to formulate a strategy.
-
Illini Company, Inc. Balance Sheet as of 12/31/20X0 Assets Current Assets: Cash $1,500,000 Accounts receivable, net 18,000 Inventory 50,000 Total current assets 1,568,000 Equipment 90,000 Goodwill...
-
What is a fact table in a data warehouse?
-
When do you use OLAP?
-
What three types of actions do users typically perform when they use OLAP software?
-
Which agencies regulate most of the products within the agri-food supply chain within the United States? Why is important to have these agencies involved in the supply chain?
-
create a Marketing 2033; In class Interview /Brand Presentation (15%) Goal : To bring together PMP development in one final verbal and visual presentation. Assignment : In a mock interview (I will be...
-
Broussard Skateboard's sales are expected to increase by 20% from $7.2 million in 2016 to $8.64 million in 2017. Its assets totaled $5 million at the end of 2016. Broussard is already at full...
Study smarter with the SolutionInn App