❮ Previous Next ❯

Command line argument:

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

❮ Previous Next ❯


  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved