Jump to content

Command-line arguments: Difference between revisions

(Jakt)
Line 1,309:
 
=={{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 {
public static void main(String[] args) {
118

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.