Command line arguments in Java

Posted on

 Java also supports command line arguments. Command line arguments are nothing but a list of values passed to the program during the execution of the program. The values passed are collected in the variable ‘args’ which is infact an array of ‘String’ objects.

import java.lang.*;
class App54
{
public static void main(String yck[])
{
for(int i=0;i<yck.length;i++)
System.out.println(yck[i]);
}
}


output:

\>javac App54.java
\>java App54 chaitanya
chaitanya
import java.lang.*;
class App55
{
public static void main(String yck[])
{
int x,y,sum;
x=Integer.parseInt(yck[0]);
y=Integer.parseInt(yck[1]);
sum=x+y;
System.out.println("the value of x is : "+x);
System.out.println("the value of y is : "+y);
System.out.println("the sum of x & Y is : "+sum);
}
}


output:

\>javac App55.java
\>java App55 10 20
the value of x is : 10
the value of y is : 20
the sum of x & Y is : 30