The command line argument is the argument passed to a program at the time of execution. To access the command-line argument inside a java program is quite easy, they are stored as string in String array passed to the args parameter of main() method.
class Test { public static void main(String[] args) { for(int i=0;i< args.length;i++) { System.out.println(args[i]); } } }
40
50
60
Let's see another example:
class Test10 { public static void main(String[] args) { String[] argh={"x","y","z"}; args=argh; for(String s:args) { System.out.println(s); } } }
1st Run:
java Test10 A B C
X
Y
2nd Run:
Java Test10 A B
X
Y
Z
3rd Run:
Java Test10 A
X
Y
Z
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc