Answered step by step
Verified Expert Solution
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 commandline parameter, reads words from a file redirected from the standard input a keyboard Scanner then it should output every nth word, spaceseparated, from the text it read in where n was specified as the program's commandline parameter. If no commandline 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 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 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.;
public class EveryNth
public static void mainString args
Check command line argumemts
if
System.out.println;
System.exit;
Create an input scanner from the standard input
Get the input
Break it into words
Display every nth word

Step by Step Solution
There are 3 Steps involved in it
Step: 1

Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2

Step: 3

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