The command line argument is the argument passed to a program at the time of execution. To access the command-line argument inside a java program is quite easy, they are stored as string in String array passed to the args parameter of main() method.

Example

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

Output

40
50
60

Let's see another example:

Example

class Test10
{
public static void main(String[] args)
{
String[] argh={"x","y","z"};
args=argh;
for(String s:args)
{
System.out.println(s);
}
}
}

Output

1st Run:
java Test10 A B C
X
Y

 

2nd Run:
Java Test10 A B
X
Y
Z

 

3rd Run:
Java Test10 A
X
Y
Z

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment