Before learning how to pass command line arguments,we first need to know about command line arguments.
While running the program any things written after the name of the class are the command line arguments.We can pass any number to the java program through command line. Arguments are delimited by the space in command line.
for example : java [class name] arg1 arg2 arg3 arg4......................................................
Parsing Numeric Command-Line Arguments
If an application needs to support a numeric command-line argument, it must convert a
String argument that represents a number, such as "100", to a numeric value. Here is a code snippet that converts a command-line argument to an int:
class cla
{
public static void main(String a[])
{int i;
if(a.length>0)
{System.out.println("commandline arguments:" );
for(int j=0;j<=a.length;j++) { i=Integer.parseInt(a[j]); System.out.println(i);} } }}
compiling and running this program code:
Number classes — Integer, Float, Double, and so on — have parseXXX String methods that convert a representing a number to an object of their type.

No comments:
Post a Comment