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
When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
DochEvi [55]
What are the options?
3 0
3 years ago
Read 2 more answers
Is a type of bullying that takes place when a person intentionally posts negative information about another that is not true
MakcuM [25]

Cyberbullying is bullying that takes place over digital devices like cell phones, ... posting, or sharing negative, harmful, false, or mean content about someone else. It can include sharing personal or private information about someone else ... as well as any negative, mean, or hurtful content

6 0
3 years ago
Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
kotegsom [21]
Hello, I am charlespierce576! I believe I might have the answer! Simple policies such as turning of off devices not in use. Also unplugging devices during a storm.
4 0
3 years ago
HELP!!!!!!!
Savatey [412]

Answer:

mouse - input

printer - output

keyboard - input

speakers - output

headset - both

6 0
3 years ago
Simpson is trying to solve an equation related to converting a decimal number to its hexadecimal form. He decides to utilize the
Murljashka [212]

Answer:

the answer is A.

6 0
3 years ago
Other questions:
  • You use Cat5e twisted pair cable on your network. Cables are routed through walls and the ceiling. A user puts a screw in the wa
    9·1 answer
  • Write a pseudo-code that keeps asking the user for a given number 'n' different of zero, then print all numbers between one &amp
    8·1 answer
  • Which computer company was named after an orchard? dell, apple, or ibm
    11·1 answer
  • Quiénes se benefician de la realidad virtual​
    12·1 answer
  • Im boing exam help please In a category-based course grading system, teachers weigh a student's performance in all courses. all
    7·2 answers
  • What is the output?
    11·1 answer
  • A folder is a collection of related of data is true or false​
    10·2 answers
  • What is the output for this program?
    12·1 answer
  • Write a program to test if an integer input from the keyboard is odd or even. Sample Run 1: Enter a Number: 78 Even Sample Run 2
    7·1 answer
  • Hi am feeling really happy just passed a test after a lot of tries :-)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!