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. The previous exercise performed a similar check using words in place of letters. In this exercise, you are to write a program that runs a similar check using lines rather than words or letters.

Write a program that reads in several lines of text and decides if the passage reads the same, whether you read the lines top to bottom or bottom to top; this is yet another kind of palindrome. For example, the following poem reads the same from top to bottom and from bottom to top: 

As I enter my time machine or maybe not,

I wonder whether free will exists.

Change?

Change!

I wonder whether free will exists—maybe not

as I enter my time machine, or ...

Consider upper- and lowercase versions of a letter to be the same letter. Consider word boundaries to be significant, so for example, the words in the first line must read the same as the words in the last line in order to pass the test (as opposed to just the letters reading the same). However, consider all word delimiters as being equivalent; i.e., a punctuation mark, any number of spaces, or any combination of these are all considered to be equivalent. The end of the passage should be marked by a line containing only the word “end,” spelled with any combination of upper- and lowercase letters and possibly with blanks before and/or after it. Your program should have a friendly interface and allow the user to check more passages until the user wishes to quit the program.

FIGURE 7.3 A Program to Recognize Palindromes Java Application Program // FILE: Palindrome.java // This program reads strings from the keyboard and determines whether each input // line is a palindrome. The program ignores everything except alphabetic letters, and it // ignores the difference between upper- and lowercase letters. import

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: