Java program to insert and print array using command line argument
- The command-line arguments are passed to the program at run-time.
- The arguments passed from the console can be received in the java program and it can be used as an input.
- To run this java program, you must pass at least one argument from the command prompt.
classCommandLineForDemo { public static void main(String args[]) { for(inti=0; i<args.length; i++) System.out.println("args[" + i + "]: " + args[i]); } }
Program Output:
java CommandLineForDemo 1 2 3 4 5 6 args[0]: 1 args[1]: 2 args[2]: 3 args[3]: 4 args[4]: 5 args[5]: 6
I hope this post helps you to understand Print array using the command line argument and its implementation in Java programming language.
Keep coding 🙂
easy code and lovely thumbnails and friendly UI