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
The PowerPoint view in which you can edit the slide master is called ______________.
nirvana33 [79]

Answer:

it's slide master view.

8 0
3 years ago
Mention five importance of taskbar​
sveticcg [70]

Answer:

The taskbar is an element of an operating system located at the bottom of the screen. It allows you to locate and launch programs through Start and the Start menu, or view any program that's currently open.

6 0
3 years ago
What formula most likely exists in D18?
gavmur [86]
<span>Cystagia from Dynamic Nutritionals is a homeopathic UTI, bladder and kidney support that promotes urinary tract health and function.</span>
4 0
3 years ago
Stream control transmission protocol (sctp) is a new _________ protocol.
Mila [183]
Stream control transmission protocol (sctp) is a new IP transport protocol.
7 0
3 years ago
For functional programming languages, the scope of a local name Group of answer choices is always the entire program. starts imm
svp [43]

Answer:

in the body part of the declaration or definition

Explanation:

In functional programming the scope of a variable is in the body part of the declaration or definition. Meaning that as soon as it is declared, whatever body it is in can call and use that variable but not any code outside of that body. For example, in the below code variable (var1) is declared inside func1 and therefore can be used by any code inside the body of func1 but not by code inside func2 since it is outside the body of func1.

void func1() {

int var1;

}

void func2() {

var1 = 2 // This will not work, since var1 is only available in func1()

}

6 0
3 years ago
Other questions:
  • The ________ multiple-selection PHP statement is used to handle decision making and can be used to replace multiple if and if...
    12·1 answer
  • Do you like PC? Why? (I need your opinion for research)
    10·2 answers
  • 3. Of the following pieces of information in a document, for which would you most likely insert a mail merge field? A. First nam
    13·2 answers
  • A ____ by a design professional is used to determine the best system to provide the appropriate level and type of protection.
    6·1 answer
  • Can y’all help me with these questions ?
    5·1 answer
  • You start up your laptop while getting a coffee across the room. You hear the usual chimes and doinks as it starts up. When you
    14·2 answers
  • If the supply of computer engineers increases at the same time that the demand for these workers decreases, what would be the MO
    7·1 answer
  • write query for all products reutrn product name with its amounts due, paid, canceled, and refunded, order the result by product
    7·1 answer
  • How does the autosum command calculate data? Need help ASAP​
    5·1 answer
  • Simple interest will always pay more interest than compound interest.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!