Java application can accept any number of arguments from the command line. Here you will be guide how to input command line arguments in Netbeans IDE.
1. Simple Java code "HelloWorld.java"
3. Output
1. Simple Java code "HelloWorld.java"
2. How to input arguments.package helloworld;public class HelloWorld {public static void main(String[] args) {System.out.println("number of input "+args.length);for (String i : args) {System.out.println(i);}}}
- File --> Project Properties(<file name>)
- Select "run"
- Enter inputs (arguments) in Arguments text field. Separate each arguments by space and click "ok".
- Note: If you enter argument including double quotes it takes as a single argument even-though separated by space.
- Ex: "go run went" is taken as single argument
- Ex: go run went <---- taken as multiple arguments.
3. Output
- Run --> Run Main Project or press shortcut key F6.
thanks mate!
ReplyDeleteYou are very welcome Ammar :)
DeleteGreat example about Java Command Line Argument
ReplyDeletethanks