Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We will work together to write a Java application EveryNth.java that takes a number as its only command - line parameter, reads words from a

We will work together to write a Java application EveryNth.java that takes a number as its only command-line parameter, reads words from a file redirected from the standard input (a keyboard Scanner), then it should output every nth word, space-separated, from the text it read in, where n was specified as the program's command-line parameter. If no command-line parameter is provided or the one provided is not a positive integer, your program should print an appropriate error message and exit. Otherwise, your program should not issue any prompts or produce any other output except the n words.
This is a good example of a place where running the program from the command line can come in handy. If you have a plain text file atest.txt with the words to use as input, you could run the program, redirecting standard input to come from the file as follows:
java EveryNth 10 atest.txt
Further, if you want to store the output of your program into a new plain text file nonsense.txt, using redirection of standard output:
java EveryNth 10 atest.txt > testOut.txt
Add your testOut.txt to your repository, and then commit and push your completed code and the output file.import java.util.*;
7
8vv public class EveryNth {
9vv public static void main(String[] args){
10
11// Check command line argumemts
if (){
System.out.println("");
System.exit(1);
}
??? Create an input scanner from the standard input
??? Get the input
// Break it into words
// Display every nth word
}
}
26
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago