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 ??
Owen Jacobson - 02 Dec 2007 23:22 GMT
> Hi
>
[quoted text clipped - 6 lines]
> 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
Arne Vajhøj - 02 Dec 2007 23:53 GMT
> 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
[quoted text clipped - 4 lines]
> 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[i].startsWith("-v")) {
version = Integer.parseInt(args[i].substring(2));
} else {
fnm = args[i];
}
}
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