In Figure 7.3, we presented a program that checks a string to see if the letters in
Question:
In Figure 7.3, we presented a program that checks a string to see if the letters in the string read the same forward and backward. These strings are called palindromes. Another kind of palindrome is one in which we look at words rather than letters. A word-by-word palindrome is a string of words such that the words read the same forward and backward. For example, the quote “You can cage a swallow, can’t you, but you can’t swallow a cage, can you?” is a word-byword palindrome. Write a program to test an input string and tell whether or not it is a word-by-word palindrome. Consider upper- and lowercase letters to be the same letter. Define a word as any string consisting of only letters or an apostrophe and bounded at each end with one of the following: a space, a punctuation mark, the beginning of the line, or the end of the line. Your program should have a friendly interface and allow the user to check more lines until the user wishes to quit the program.
public static boolean is_palindrome (String input) // The return value is true if and only if the input string is a palindrome. // All non-letters are ignored, and the case of the letters is also ignored. // See page 365 for an explanation of using Java's LinkedList class as a queue. { Queue q = new LinkedList( ); Stack s new Stack( ); Character letter; int mismatches %3D // One character from the input string 0; // Number of spots that mismatched // Index for the input string int i; for (i = 0; i < input.length( ); i++) { letter = input.charAt (i); if (Character.isLetter(1etter)) { q. add (letter); s.push(letter); } } %3D while (!q.isEmpty( )) { if (q.remove (O !- s.pop( )) mismatches++; } // If there were no mismatches, then the string was a palindrome. return (mismatches = 0); } }
Step by Step Answer:
Heres an implementation in Python of the program described in the problem statement import string de...View the full answer
Students also viewed these Computer science questions
-
Test the following function to determine whether or not it is a binomial probability function. List the distribution of probabilities and sketch a histogram. Tr)-C)(1).(1 5-x for x = 0, 1, 2, 3, 4, 5
-
For each of the following, tell whether or not you would expect it to have a strong seasonal component and why. a. Sales of colorful wrapping paper, recorded monthly. b. The number of air travelers...
-
For each item listed, state whether or not it would be disclosed for each of the reportable segments, identify the segments for which it would be disclosed and explain what other disclosures, if any,...
-
The accompanying data are consistent with summary statistics that appeared in the paper Shape of Glass and Amount of Alcohol Poured: Comparative Study of Effect of Practice and Concentration (...
-
A sample of 20 chocolate chip cookies was taken from a box. The cookies were examined for the number of chocolate chips in each cookie. The numbers recorded were 18 15 17 17 16 18 16 15 16 14 16 17...
-
Homework Assignment: Answers must be accurate before posting! Chapter8:CompleteExcel-BasedProblem8-13fromyourtext(seetextquestionattached)usingthetemplateprovidedinthisweek'smodule(seeattached)....
-
elaboration, in which we use crosstabulations across multiple groups
-
Hydrogen gas is used in a process to manufacture a sheet material of 6-mm thickness. At the end of the process, H2 remains in solution in the material with a uniform concentration of 320 k mol/m3. To...
-
Mount Inc. was a hardware store that operated in Boise, Idaho. Management made some poor inventory acquisitions that loaded the store with unsalable merchandise. Due to the decline in revenues, the...
-
Sequel Theatre, owned by Nadia Fedkovych, is unique as it shows only movies that are part of a theme with sequels. As at June 30, 2014, the ledger of Sequel Theatre showed the following: Cash,...
-
Heres a new idea for implementing the sequence class from Section 4.5. Instead of the items being stored on a linked list, they will be stored using two stacks as private member variables with the...
-
In Figure 7.3, we presented a program that checks a string to see if the letters in the string read the same forward and backward. The previous exercise performed a similar check using words in place...
-
Determine the reactions at A and E. 6 in. 4 in. C B 5 in. A 200 lb OD 10 in. - OE
-
The table below shows the population of Mozambique between 1960 and 2010. This data can be modelled using an exponential function of the form P = ab t , where t is the time in years since 1960 and a...
-
Southco is a medium-sized American-owned global manufacturer of access hardware solutions, such as latches and hinges, used for applications in the aircraft, railway, computer and automotive...
-
To what extent do staffing processes at the Dionysos reflect the strategic approach to recruitment and selection encapsulated by the conceptual framework and model depicted in Key Concepts 8.4 and...
-
Im an accounting major, not an operations expert, yelled just-promoted Bob Barthrow, the executive vice president of the Midwest Frequent Flyer Call Center, during a senior-level management meeting....
-
The Hudson Jewelers case study can be found in Appendix C. Chapter 14 Case Question for Discussion: 1.Customer demand (weekly visits) at Hudson Jewelers is highly seasonal, as shown in the worksheet...
-
Compute 8 P 5 .
-
"Standard-cost procedures are particularly applicable to process-costing situations." Do you agree? Why?
-
What is the largest integer m such that every simple connected graph with n vertices and n edges contains at least m different spanning trees? A. 1 B. 2 C. 3 D. n
-
How does depth first traversal work?
-
Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G containing the edge e. Which of the following statements is always...
-
You have just been hired as a new management trainee by Earrings Unlimited, a distributor of earrings to various retail outlets located in shopping malls across the country. In the past, the company...
-
Brief Exercise 10-6 Flint Inc. purchased land, building, and equipment from Laguna Corporation for a cash payment of $327,600. The estimated fair values of the assets are land $62,400, building...
-
"faithful respresentation" is the overriding principle that should be followed in ones prepaparation of IFRS-based financial statement. what is it? explain it fully quoting IAS. how this this...
Study smarter with the SolutionInn App