Command line argument

J

joe

Hi

I was if " -v " flag means anything in comand line argument. In our
project they told us to right the comman line argument in this
forum...

java WorPairCounter -vN FileName

And N stands for either 1 or 2 . So were are asked to check if N is 1
or 2 , so is there any way to check it ??
 
O

Owen Jacobson

Hi

I was if " -v " flag means anything in comand line argument. In our
project they told us to right the comman line argument in this
forum...

java WorPairCounter -vN FileName

And N stands for either 1 or 2 . So were are asked to check if N is 1
or 2 , so is there any way to check it ??

Command line arguments are passed as-tokenized to the main method as a
string array. In your case, you'd get the following as your args array:

{"-v1", "FileName"}
or
{"-v2", "FileName"}

-o
 
A

Arne Vajhøj

joe said:
I was if " -v " flag means anything in comand line argument. In our
project they told us to right the comman line argument in this
forum...

java WorPairCounter -vN FileName

And N stands for either 1 or 2 . So were are asked to check if N is 1
or 2 , so is there any way to check it ??

public static void main(String[] args) {
if(args.length == 2) {
int version = 0;
String fnm = null;
for(int i = 0; i < args.length; i++) {
if(args.startsWith("-v")) {
version = Integer.parseInt(args.substring(2));
} else {
fnm = args;
}
}
if(version > 0 && fnm != null) {
System.out.println("version=" + version);
System.out.println("fnm=" + fnm);
} else {
System.out.println("Usage: java WPCr -vn filename");
}
} else {
System.out.println("Usage: java WPC -vn filename");
}
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top