Reading Command Line Arguments
-
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"); } } }
-
Another
for
loop syntaxclass 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"); } } }