Answered step by step
Verified Expert Solution
Link Copied!

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 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

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_2

Step: 3

blur-text-image_3

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

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago