Using an approach similar to that in Worked Example 19.1, find all words with length of at
Question:
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 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 vilg ther imagi Step 3 Transform the stream. 7zle iStock.com/tigermad. try (Stream- lines = Files. lines (Paths.get("words.txt"))) { every lopr kuo 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% (1 review)
Answered By
Gauri Hendre
I worked as EI educator for Eduphy India YT channel. I gave online tutorials to the students who were living in the villages and wanted to study much more and were preparing for NEET, TET. I gave tutions for topics in Biotechnology. I am currently working as a tutor on course hero for the biochemistry, microbiology, biology, cell biology, genetics subjects. I worked as a project intern in BAIF where did analysis on diseases mainly genetic disorders in the bovine. I worked as a trainee in serum institute of India and Vasantdada sugar institute. I am working as a writer on Quora partner program from 2019. I writing on the topics on social health issues including current COVID-19 pandemic, different concepts in science discipline. I learned foreign languages such as german and french upto A1 level. I attended different conferences in the science discipline and did trainings in cognitive skills and personality development skills from Lila Poonawalla foundation. I have been the member of Lila poonawalla foundation since 2017. Even I acquired the skills like Excel spreadsheet, MS Office, MS Powerpoint and Data entry.
5.00+
4+ 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 exactly one vowel (which might be repeated). What is the longest one? How many such words exist for each length? Data...
-
Although the death penalty in India has similarities to the United States, the Indian Supreme Court and the Presidents of India have successfully halted nearly all executions. How have t he Supreme...
-
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...
-
First Ownership orders merchandise from several suppliers from around the world. Each of the suppliers has different shipping or transportation terms. At the end of December, First Ownership had the...
-
A heat engine cycle is executed with steam in the saturation dome between the pressure limits of 5 and 2 MPa. If heat is supplied to the heat engine at a rate of 380 kJ/s, the maximum power output of...
-
Why does Java not have destructors?
-
Quilts R Us (QRU) is considering investing in a new patterning attachment with the cash flow profile shown in the table below. QRU's MARR is 13.5 percent/year. a. What is this investment's external...
-
Ellen Bright, CEO of TWA Parts (TWAP), looked at the two balanced scorecards before her. One, from the luxury division, showed strong financial results; while the other, from the economy division,...
-
We read about Language and Authority in grammar and how some groups try to control language. Identify one such group and explain how and why they try to control language. Do you think such efforts to...
-
Paoli Consulting is a consulting firm owned and operated by Mary Paoli. The following end-of-period spreadsheet was prepared for the year ended March 31, 2019: During the year ended March 31, 2019,...
-
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...
-
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....
-
A machine is designed to fill 16-ounce bottles of shampoo. When the machine is working properly, the amount poured into the bottles follows a Normal distribution with mean 16.05 ounces and standard...
-
What does MedPAC stand for, and what is its purpose?
-
What are the major differences between investor-owned and not-for-profit corporations?
-
What is a probability distribution?
-
From the following information ascertain the opening balance of sundry debtors and closing balance of sundry creditors. The rate of gross profit is 25% on selling price and out of the total sales Rs....
-
Draw block diagram showing the main components of a computer.
-
For a firm that you know well, give an example SO Strategy, showing how an internal strength can be matched with an external opportunity to formulate strategy.
-
B.) What is the approximate concentration of free Zn 2+ ion at equilibrium when 1.0010 -2 mol zinc nitrate is added to 1.00 L of a solution that is 1.080 M in OH - . For [Zn(OH) 4 ] 2- , K f = 4.610...
-
What is an OODBMS?
-
What is a domain?
-
How do classes relate to objects?
-
Trust promotes loyalty within an organisation, and between an organisation and its external stakeholders. In light of this statement, evaluate the meaning of trust and the role of ethics in building...
-
Suppose a State of California bond will pay $1,000 eight years from now. If the going interest rate on these 8-year bonds is 6.2%, how much is the bond worth today?
-
Identify some ways global advertising campaigns benefit a company. How can we ensure these campaigns are net benefits? (Think cultural considerations.)
Study smarter with the SolutionInn App