Pageviews

Thursday 6 June 2013

Execute Java code using Command line Arguments

by Unknown  |  in Java at  Thursday, June 06, 2013

Command Line arguments is one of the simple ways to execute Java code.In this method,we write out code in a simple Text editor say Notepad,only few things are different in Command line argument method as compared to codes written in IDEs.Command line is recommended for beginners only as it makes them to perfect that method and further they can move onto IDEs.Then the code written in Text editor is saved with .Java extension and is executed by Java compiler.To illustrate this we are providing a simple example of adding 2 nos.

WAP to add 2 numbers using Command line arguments


class add

{
public static void main(String args[])
{
int i,j,k;
i=Integer.parseInt(args[0]);
j=Integer.parseInt(args[1]);
k=i+j;
System.out.println("Sum is "+k);
}
}


The Output goes here:


Command line arguments



0 comments:

Proudly Powered by Blogger.