Command Line Arguments In Java:-
Comand Line Argument means the passing the arguments through the main method.
Let's take example and then we can get more clarirty on that on that topic.
![]() |
| what is Command line arguments or cmd in java with exapmle |
Exapmle:-
class CLA2
{
public static void main(String args[])
{
call(args);
}
static void call(String ss[])
{
int size=ss.length;
System.out.println("\nsee the elements of array");
for(int i=0;i<size;i++)
{
System.out.println(ss[i]);
}
}
}
From this exmple i have shown that the how to take the inputs through the command line argument.As we are using the various methods or various classess to take the input from the user like this through the command line argument we can take the input from the user but here we d ont have to import any classess and we dont have to use any methods.Here at the time of the programs execution we take the input fro the user from which we can do various operation.
Take the another example for the command line argument
Example 2:--
class CLA
{
public static void main(String args[])
{
System.out.println("Enter something ");
for(int i=0;i<args.length;i++)
{
System.out.println(args[i]);
}
}
}
Here in this program at the time of programs execution or after the compilation of the program we can take the command line arguments.Here to know the size of the array or the command line argumnets we can use the "length" keyword .
Example 3:-
Here some another example of the command Line Argument
class CommandLineArgumentDemo
{
public static void main(String args[])
{
int a=0;
int b=args.length;
while(a++<b)
{
System.out.println(args[a]);
}
}
}
Example 4:-
class CommandLineArgumentOutSideMain
{
public static void main(String args[])
{
call(args);
}
static void call(String ss[])
{
int size=ss.length;
System.out.println("See the command line argument.");
for(int i=0;i<size;i++)
{
System.out.println(ss[i]);
}
}
}
Pratice this programs on your computer we can get more clarity on this topic.My special suggesion is plz keep pratice all the java progarms beacuse it prety difficult to remember all the progarms we just have to keep some concept on your mind.So keep pratice and comment me if You are facing any problem in the code given.
Next--Constructos in java(click here)


No comments:
Post a Comment