Sometimes need to pass information into a program when run it. This is accomplished by passing command-line arguments to main ().
A command-line argument is the information that directly follows the program’s name on the command line when it is executed.
In java they are stored as string in the string array passed to main ().
Ex,
class Comm
{
public static void main (string args[])
{
for (int i=0; i<args.length; i++)
{
System.out.println (“args: “+args[i]);
}
}
}
Executing this program.
Java comm. This is a 1 prg.
Output:-
args: 0: This
args: 1:is
args: 2: a
args: 3:1
args: 4: prg
Note:-
All command line arguments are passed as string must be numeric values to their internal forms manually.
Posted by :Ruchita Pandya
No comments:
Post a Comment