***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***

posts

    Command-Line Arguments

    A Java application can accept any number of arguments from the command line. The java command-line argument is an argument i.e. passed at the time of running the java program. The arguments passed from the console can be received in the java program and it can be used as an input.

    Example:

    class CommandLineEx{  

    public static void main(String args[]){  

    System.out.println("First argument is: "+args[0]);  

    }  

    }  

    To run this java program, at least one argument must be passes from the command prompt.

    javac CommandLineEx.java    //compiling

    java CommandLineEx hai   //run

    Example program to print multiple parameters:

    class A{  

    public static void main(String args[]){    

    for(int i=0;i<args.length;i++)  

    System.out.println(args[i]);   

    }  

    }  

    javac A.java  

    java A Ashraf  Msc Mtech

    No comments:

    Post a Comment