1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nataly862011 [7]
3 years ago
12

You should process the tokens by taking the first letter of every fifth word,starting with the first word in the file. Convert t

hese letters to uppercase andappend them to a StringBuilder object to form a word which will be printedto the console to display the secret message.
Computers and Technology
1 answer:
zhenek [66]3 years ago
5 0

Answer:

See explaination

Explanation:

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

import java.util.StringTokenizer;

public class SecretMessage {

public static void main(String[] args)throws IOException

{

File file = new File("secret.txt");

StringBuilder stringBuilder = new StringBuilder();

String str; char ch; int numberOfTokens = 1; // Changed the count to 1 as we already consider first workd as 1

if(file.exists())

{

Scanner inFile = new Scanner(file);

StringTokenizer line = new StringTokenizer(inFile.nextLine()); // Since the secret.txt file has only one line we dont need to loop through the file

ch = line.nextToken().toUpperCase().charAt(0); // Storing the first character of first word to string builder as mentioned in problem

stringBuilder = stringBuilder.append(ch);

while(line.hasMoreTokens()) { // Looping through each token of line read using Scanner.

str= line.nextToken();

numberOfTokens += 1; // Incrementing the numberOfTokens by one.

if(numberOfTokens == 5) { // Checking if it is the fifth word

ch = str.toUpperCase().charAt(0);

stringBuilder = stringBuilder.append(ch);

numberOfTokens =0;

}

}

System.out.println("----Secret Message----"+ stringBuilder);

}

}

}

You might be interested in
How do we explain the difference between fake news and facts​
Natalija [7]

Answer: it depends if the news is on the news and someone rights an article about it and says some mislead details that's how u know its fake  

Explanation:

3 0
3 years ago
TWO QUICK QUESTIONS
andrezito [222]
I'm guessing 8? But I'm not 100% positive 
5 0
3 years ago
I can't find my grandson someone help
Artemon [7]

Answer:

i'm right here

Explanation:

grandma

8 0
2 years ago
Read 2 more answers
software that instructs the computer how to run applications and controls the display/keyboard is know as the___.
kakasveta [241]
The answer is the alu arithmetic logic unit.
8 0
3 years ago
The larget social networking site to date is
maks197457 [2]
FB, I would guess.

Sincerely,

Xeno
3 0
3 years ago
Other questions:
  • Which OS, in your opinion, manages multiprocessing in the most efficient manner?
    14·1 answer
  • In JAVA,
    10·1 answer
  • Wich technology can a website use to allow you to listen to a concert live over the internet?
    10·1 answer
  • Which statement is true about the purpose of a work in process constraint?
    15·1 answer
  • What should be used to screw on broadheads? needle-nose pliers gloves thumb and forefinger only specially designed wrench
    6·1 answer
  • Please help if you answer correcly i will give you brainelst!!!!!!!!!!!!!!!!!!
    6·2 answers
  • You defined a class and saved it as shoe.py.
    5·2 answers
  • Cloud architects have been largely replaced by ScrumMasters.<br><br> True<br><br> False
    15·2 answers
  • Which of the following are drivers of machine learning growth?
    15·1 answer
  • Who is the best valorant character
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!