class PrintArgs {
public static void main (String args[]) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}
}
$ java PrintArgs Hello there!
Hello
there!
System.out.println()
prints its arguments followed
by a platform dependent line separator (carriage return (ASCII 13,
\r
) and a linefeed (ASCII 10, \n
) on Windows, linefeed on Unix,
carriage return on the Mac)
System.err.println()
prints on standard err
instead.
You can concatenate arguments to println()
with a
plus sign (+
), e.g.
System.out.println("There are " + args.length + " command line arguments");
Using print()
instead of println()
does
not break the line. For example,
System.out.print("There are ");
System.out.print(args.length);
System.out.print(" command line arguments");
System.out.println();
System.out.println()
breaks the line and flushes the
output. In general nothing will actually appear on the screen until
there's a line break character.