In java command line arguments are used to accept inputs from the keyboard.
Q.1.Write a program then add two numbers using command line arguments in java.
class Sibani
{
public static void main(String args[])
{
int a,b,c=0;
a=Integer.parseInt(args[0]);
=Integer.parseInt(args[1]);
c=a+b;
System.out.println("Addition is"+c);
}
}
How to compile?
After compilation then run java program
(Remember while inputting any number using command line arguments user must to give a between space java command and number.
class Kunu
{
public static void main(String args[])
{
int no=1,n;
n=Integer.parseInt(args[0]);
while(no<=n)
{
System.out.println(+no);
no++;
}
}
}
No comments:
Post a Comment