Java Reference
In-Depth Information
Programming Assignments
1 Processing Palindromes with StringBuffers
Palindromes are words spelled the same way backwards as they are forwards,
such as dad or mom. Using methods from the String and StringBuffer classes,
write a program that will accept input from the keyboard and then determine if
the entered word is a palindrome. The program should continue as long as the
user enters any values. For an extra challenge, modify the program to determine
if a phrase is a palindrome. For simplicity, do not use punctuation and remove
embedded spaces. Hint: You can use a StringBuffer method to delete an individ-
ual character at a specified index. Figure 9-48 displays sample output from the
program.
FIGURE 9-48
2 Using String Methods to Count Characters
Generally, word processing programs can count and then display the number of
characters in a document, either including or excluding blank characters. Using
methods from the String class, write a program that will accept input from the
keyboard and then display three values: (1) the count of all characters in the
string, including leading and trailing blanks; (2) the count of characters not
including leading and trailing blanks; and (3) the count of all non-blank charac-
ters. The program should continue as long as the user enters any values, even if
only spaces are entered. Figure 9-49 displays sample output from the program.
Search WWH ::




Custom Search