Sunday, November 2, 2014

Filled Under: , ,

Program to add two numbers using command line argument.

Share


Code Box
-----------------------------

/*Program to add two numbers using command line argument */

class add
{
public static void main(String x[])
{
int a,b,c,d;

System.out.print("\nzeroth argument :"+x[0]);
a=Integer.parseInt(x[0]);
//zeroth argument in a
System.out.print("\nvalue of a= "+x[0]);


System.out.print("\nfirst argument :"+x[1]);
b=Integer.parseInt(x[1]);
//first argument in b
System.out.print("\nvalue of b= "+x[1]);

c=a+b;

System.out.print("\nSum of a+b= "+c);

d=Integer.parseInt(x[0])+Integer.parseInt(x[1]);
System.out.print("\nSum of arguments is ="+d);

}
}

0 comments:

Post a Comment