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
Edmund wants to visit his office website. Which software application would he use?
ollegr [7]
He would use a browser!
3 0
4 years ago
Read 2 more answers
Assignment 1 silly sentences
ololo11 [35]

Answer:

Sally sells sea shells by the sea shore

Explanation:

3 0
3 years ago
Jan pays $70 each month for her auto insurance policy. this regular payment is called a: co-pay, deductible, premium, claim?
balu736 [363]
Co-pay: Term often used in health care, insurance covers part of the cost and you pay the rest. Seeing in this situation you are paying for the insurance itself, the term is not correct. 

Deductible: An insurance term for when you have to pay a certain amount before insurance will cover the rest. 

Premium: A fee payed by the insured (Jan) to be covered. This is my best guess for your answer.

Claim: A claim is when Jan would request the insurance company to reimburse her after a car accident (or her tires got slashed, etc.)
3 0
3 years ago
Assume you have thefollowing declaration int beta[50];.Which of the following is a valid elementof beta?
ANEK [815]

Answer:

A - beta[0]

Explanation:

Beta[0] is the first element of the array, therefore automatically it is a valid element of beta. B and C are disqualified because you would not use single quotations when referring to an element. D is disqualified because the element starts at 0 (beta[0]) and has 50 elements declared, therefore it would end at 49, with beta[49] being the last element.

4 0
3 years ago
The Smith family has five children who work in a variety of careers. They include a Building Designer, an Astrophysicist, a Comp
Viefleur [7K]

The correct answer is the Science, Technololy, Engineering and Math career cluster.

All of the five careers that are listed fall into the career cluster that is called Science, Technology, Engineering and Math. People working in this career cluster could work in science labs, design products and systems, or support scientists or mathematicians in their work.

7 0
3 years ago
Read 2 more answers
Other questions:
  • An intranet is a way for a company or organization to protect copyrighted and other important information?
    15·2 answers
  • In order to install a device, the operating system needs the required __________ for that device.
    15·2 answers
  • Which of the following is NOT true about functions? They go below the main program in the source code file. They do a single tas
    10·1 answer
  • 3. Run the C-LOOK algorithm (requests can only be serviced when the head is moving toward higher numbered tracks); the head is c
    11·1 answer
  • Leonardo is having difficulty accessing the course website. he should contact the for assistance. (points:1)
    13·1 answer
  • How does the variable scope influence the structure of an algorithm
    7·1 answer
  • Miley met up with a bunch of her college friends after several years. She told them that she works for the sound department of a
    5·1 answer
  • Suppose that you have been asked to create an information system for a manufacturing plant that produces nuts and bolts of many
    12·1 answer
  • . In the ____, you justify acquiring newer and better resources to investigate computer forensics cases.
    14·1 answer
  • In what year was the earliest documented use of the word computer?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!