Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Command line argument

Reply
Thread Tools

Command line argument

 
 
joe
Guest
Posts: n/a
 
      12-02-2007
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 ??
 
Reply With Quote
 
 
 
 
Owen Jacobson
Guest
Posts: n/a
 
      12-02-2007
On 2007-12-02 15:19:14 -0800, joe <(E-Mail Removed)> said:

> 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

 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-02-2007
joe wrote:
> 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[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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -jar ignore the classpath command line argument Thomas Kellerer Java 5 04-13-2005 12:01 PM
Command line argument problems Justin Naidl C++ 2 09-18-2004 04:08 PM
Program cannot recognize asterisk(*) as an argument passed from the command line? Fong Java 3 05-27-2004 01:55 AM
ANNOUNCE: SCons 0.94 adds command-line argument features, fixeskey bugs Steven Knight Python 0 11-07-2003 04:56 PM
reading in command line argument nic977 C Programming 13 09-22-2003 02:50 AM



Advertisments