Thursday, 2 April 2015

Command Line Argument And Parsing Methods In Java

Java can accept many inputs at command line which can be stored in variable using parsing methods and can be easily used in programs this tutorials shows parsing methods this should be noted that no parsing method require for string and other require it.

COMMAND LINE ARGUMENT IN JAVA:

Command line argument allows the user to enter large number of argument when running the application command line argument is entered after the name of class to be run as you can see in the below program that command line argument is entered after biob (class name).

CODING:

class biob
{
public static void main(String args[])
{
String str = args[0];
int a=Integer.parseInt(args[1]);
float fl=Float.parseFloat(args[2]);
double doub=Double.parseDouble(args[3]);
short sho=Short.parseShort(args[4]);
byte by=Byte.parseByte(args[5]);
long lo=Long.parseLong(args[6]);
System.out.println("Strnig:"+str);
System.out.println("Int Data:"+a);
System.out.println("Double Number:"+doub);
System.out.println("Short Number:"+sho);
System.out.println("Byte Number:"+by);
System.out.println("Long Number:"+lo);
System.out.println("Float Number:"+fl);

}
}


OUTPUT:






No comments:

Post a Comment