Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the program below to allow it to extract ALL of the words / tokens that are supplied as command line parameters to your program.
Complete the program below to allow it to extract ALL of the wordstokens
that are supplied as command line parameters to your program.
You will put the string that you are wanting to pass to your program
inside double quotes so it will be passed, intact, as a single
command line parameter see sample output below
One simplifying assumption that we will make is that all of our data
will have exactly one space between words and no spaces at the beginning
or end of the string. again see sample output below
I've provided you with a start for your program. You do not need to
write any additional classes or methods.
No spilt or for loop, Has to be a WHILE LOOP
public class Lab
public static void mainString args
if argslength
System.out.printlnusage: LabSTRING IN QUOTES;
System.exit;
String str args;
OUTPUT
$ java Lab
usage: Lab "STRING IN QUOTES"
$ java Lab
$ java Lab "hello"
hello
$ java Lab "hello world"
hello
world
$ java Lab "this is a test"
this
is
a
test
My Code
public class Lab
public static void mainString args
if argslength
System.out.printlnusage: LabSTRING IN QUOTES;
System.exit;
String str args;
Int i ;
Int j;
whilej strindexOf start
String token strsubstringi j;
System.out.printlntoken;
i j;
String lastToken strsubstringi;
System.out.printlnlastToken;
Its not printing anything though
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