Question:
How can you print out all the command line arguments in java?
Answer:
Use a while loop.
Code:
public class PrintArgs { public static void main(String[] args) { int i = 0; while(i < args.length) { System.out.println("arg[" + i + "]: " + args[i]); i++; } } }
Output:
$ java PrintArgs The cat in the hat arg[0]: The arg[1]: cat arg[2]: in arg[3]: the arg[4]: hat