What is command line argument?

To passing a value at runtime to main method called command line argument. Any type value we can pass in main array argument.

Example of cammand line argument:

	class Test
		public static void main(String args[])
			int n = args.length;
			for(int i=0; i<n; i++)
				System.out.println("args["+i+"] = "+args[i]);


	C:\Users\Nature\Desktop\Java>javac Test.java

	//passing a value at runtime to an array in main method.
	C:\Users\Nature\Desktop\Java>java Test 1 2 3 4
	args[0]= 1
	args[1]= 2
	args[2]= 3
	args[3]= 4

Advertisement here

Share this Page.