Sunday, December 19, 2010

Java- Reading Command Line Arguments

Reading Command Line Arguments
(i) Common way
class ReadCmdLineArgs {
public static void main(String[] args) {
System.out.println("Command Line Args:");
System.out.println("------------------");
if (args.length != 0) {
for (int i = 0; i < args.length; i++) {
System.out.println((i + 1) + ". " + args[i]);
}
} else {
System.out.println("No command line args. specified");
}
}
}
(ii) Another for loop syntax
class ReadCmdLineArgs {
public static void main(String[] args) {
System.out.println("Command Line Args:");
System.out.println("------------------");
if (args.length != 0) {
int i = 1;
for (String arg : args) {
System.out.println((i++) + ". " + arg);
}
} else {
System.out.println("No command line args. specified");
}
}
}

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

The Insane Techie - Android App

Launched an android app for the blog on 07th June 2016. Get it from google play store... Tips for using the app Use in landscape mo...