Command-line arguments: Difference between revisions

Content added Content deleted
(Jakt)
Line 1,309: Line 1,309:


=={{header|Java}}==
=={{header|Java}}==
<syntaxhighlight lang="java">

/* arguments are passed to the program via 'main' */
public static void main(String[] args) {
/* 'args' is non-null */
for (String arg : args)
System.out.println(arg);
}
</syntaxhighlight>
Running this command
<syntaxhighlight lang="bash">
myprogram -c "alpha beta" -h "gamma"
</syntaxhighlight>
Will produce the following
<pre>
-c
alpha beta
-h
gamma
</pre>
<br />
And alternate demonstration.
<syntaxhighlight lang="java">public class Arguments {
<syntaxhighlight lang="java">public class Arguments {
public static void main(String[] args) {
public static void main(String[] args) {