We will need to use a variety of Character class and String class methods to validate the data and separate it in order to process it. We will also use a Character class method to allow the user to continue the program if desired. The String class’s split method will allow us to process the tokens in a text file in order to decode a secret message. We will use the first letter of every 5th token read in from a file to reveal the secret message. Task #2 String.split and the StringBuilder Class 1. Copy the file secret.txt (Code Listing 9.3) from the Student Files or as directed by your instructor. This file is only one line long. It contains 2 sentences. 2. Write a main method that will read the file secret.txt, separate it into word tokens. 3. You should process the tokens by taking the first letter of every fifth word, starting with the first word in the file. Convert these letters to uppercase and append them to a StringBuilder object to form a word which will be printed to the console to display the secret message. Code Listing 9.3 (secret.txt) January is the first month and December is the last. Violet is a purple color as are lilac and plum.
We will need to use a variety of Character class and String class methods to
validate the data and separate it in order to process it. We will also use a Character
class method to allow the user to continue the program if desired.
The String class’s split method will allow us to process the tokens in a text file in
order to decode a secret message. We will use the first letter of every 5th token read in
from a file to reveal the secret message.
Task #2 String.split and the StringBuilder Class
1. Copy the file secret.txt (Code Listing 9.3) from the Student Files or as directed by
your instructor. This file is only one line long. It contains 2 sentences.
2. Write a main method that will read the file secret.txt, separate it into word
tokens.
3. You should process the tokens by taking the first letter of every fifth word,
starting with the first word in the file. Convert these letters to uppercase and
append them to a StringBuilder object to form a word which will be printed
to the console to display the secret message.
Code Listing 9.3 (secret.txt)
January is the first month and December is the last.
Violet is a purple color as are lilac and plum.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images