Upload
kumarishu125
View
213
Download
0
Embed Size (px)
Citation preview
7/27/2019 Objectofoop
1/5
7/27/2019 Objectofoop
2/5
7/27/2019 Objectofoop
3/5
7/27/2019 Objectofoop
4/5
1. Command Line Argument2. Simple example of command-line argument3. Example of command-line argument that prints all the values
The command-line argument is an argument passed at the time of running the javaprogram. The argument can be received in the program and used as an input. So, itprovides an convenient way to check out the behaviour of the program on differentvalues. You can pass N numbers of arguments from the command prompt.Simple example of command-line argumentIn this example, we are receiving only one argument and printing it. For running thisprogram, you must pass at least one argument from the command prompt.
class A{public static void main(String args[]){
System.out.println("first argument is: "+args[0]);
}}
compile by > javac A.java
run by > java A sonoo
Output:first argument is: sonoo
Example of command-line argument that prints all the valuesIn this example, we are printing all the arguments passed from the command-line. Forthis purpose, we have traversed the array using for loop.
class A{public static void main(String args[]){
for(int i=0;i javac A.java
7/27/2019 Objectofoop
5/5
run by > java A sonoo jaiswal 1 3 abc
Output: sonoojaiswal
13abc