Question: 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 words/tokens
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 Lab4
{
public static void main(String args[])
{
if (args.length !=1)
{
System.out.println("usage: Lab4\"STRING IN QUOTES\"");
System.exit(0);
}
String str = args[0];
//
}
}
= OUTPUT ==============================================================
$ java Lab4
usage: Lab4 "STRING IN QUOTES"
$ java Lab4""
$ java Lab4 "hello"
[hello]
$ java Lab4 "hello world"
[hello]
[world]
$ java Lab4 "this is a test"
[this]
[is]
[a]
[test]
===My Code=======
public class Lab4
{
public static void main(String args[])
{
if (args.length !=1)
{
System.out.println("usage: Lab4\"STRING IN QUOTES\"");
System.exit(0);
}
String str = args[0];
Int i =0;
Int j;
while((j = str.indexOf(, start))!=-1)
{
String token = str.substring(i, j);
System.out.println(token);
i = j+1;
}
String lastToken = str.substring(i);
System.out.println(lastToken);
}
}
(Its not printing anything though)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!