Java Reference
In-Depth Information
14.13 (Tokenizing and Comparing String s) Write an application that reads a line of text, token-
izes the line using space characters as delimiters and outputs only those words beginning with the
letter " b ".
14.14 (Tokenizing and Comparing String s) Write an application that reads a line of text, token-
izes it using space characters as delimiters and outputs only those words ending with the letters " ED ".
14.15 (Converting int Values to Characters) Write an application that inputs an integer code for
a character and displays the corresponding character. Modify this application so that it generates all
possible three-digit codes in the range from 000 to 255 and attempts to print the corresponding
characters.
14.16 (Defining Your Own String Methods) Write your own versions of String search methods
indexOf and lastIndexOf .
14.17 (Creating Three-Letter String s from a Five-Letter Word) Write an application that reads a
five-letter word from the user and produces every possible three-letter string that can be derived
from the letters of that word. For example, the three-letter words produced from the word “bathe”
include “ate,” “bat,” “bet,” “tab,” “hat,” “the” and “tea.”
Special Section: Advanced String-Manipulation Exercises
The preceding exercises are keyed to the text and designed to test your understanding of funda-
mental string-manipulation concepts. This section includes a collection of intermediate and
advanced string-manipulation exercises. You should find these problems challenging, yet entertain-
ing. The problems vary considerably in difficulty. Some require an hour or two of application writ-
ing and implementation. Others are useful for lab assignments that might require two or three
weeks of study and implementation. Some are challenging term projects.
14.18 (Text Analysis) The availability of computers with string-manipulation capabilities has re-
sulted in some rather interesting approaches to analyzing the writings of great authors. Much atten-
tion has been focused on whether William Shakespeare ever lived. Some scholars believe there's
substantial evidence indicating that Christopher Marlowe actually penned the masterpieces attrib-
uted to Shakespeare. Researchers have used computers to find similarities in the writings of these
two authors. This exercise examines three methods for analyzing texts with a computer.
a)
Write an application that reads a line of text from the keyboard and prints a table indi-
cating the number of occurrences of each letter of the alphabet in the text. For example,
the phrase
To be, or not to be: that is the question:
contains one “a,” two “b's,” no “c's,” and so on.
b)
Write an application that reads a line of text and prints a table indicating the number
of one-letter words, two-letter words, three-letter words, and so on, appearing in the
text. For example, Fig. 14.25 shows the counts for the phrase
Whether 'tis nobler in the mind to suffer
c)
Write an application that reads a line of text and prints a table indicating the number
of occurrences of each different word in the text. The application should include the
words in the table in the same order in which they appear in the text. For example, the
lines
To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
contain the word “to” three times, the word “be” two times, the word “or” once, etc.
 
Search WWH ::




Custom Search