(i) Common way
class ReadCmdLineArgs {(ii) Another for loop syntax
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");
}
}
}
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