Home‎ > ‎Applied Core Java‎ > ‎Introduction‎ > ‎

Hello All

Problem : Write a program that takes more than one command line argument ?

Program :

Step 1 - Coding

Create a text file c:\sunilos\HelloAll.java  and copy below contents.

/*

 * A program which take any no. of command line argument.
 */

public class HelloAll {

    public static void main(String[] args) {

        for (int i = 0; i < args.length; i++) {
            System.out.println(i + " = Hello " + args[i]);
        }

    }
}

Step 2 - Deployment

  1. Create a folder 'c:\sunilos'. 
  2. Create or copy HelloAll.java  into 'c:\sunilos' folder.
  3. Open your command prompt and go to  'c:\sunilos'
  4. Compile HelloAll.java with help of 
    • javac HelloAll.java command. Command will create class file in the same folder.
  5. Congratulations!! your Java program is ready to serve.

Step 3 - Testing

  1. Make sure you are on Command Prompt under c:\sunilos directory
  2. Now start your java program from command prompt with help of 
    • java HelloAll Sunil OS command.

Output


It will Display
0 = Hello Sunil
1 = Hello OS



<<Previous | Next>>

ċ
Prachi Pacharne,
Oct 16, 2015, 6:48 AM
Comments