Java Reference
In-Depth Information
Output
println
. The items that are out-
put can be quoted strings, variables, numbers, or almost any object you can define in Java.
To output more than one item, place a plus sign between the items.
You can output one line to the screen using
System.out.println
SYNTAX
System.out.println(
Item_1
+
Item_2
+ ... +
Last_Item
);
EXAMPLE
System.out.println("Welcome to Java.");
System.out.println("Elapsed time = " + time + " seconds");
produce the same output as our previous example:
A wet bird
never flies at night.
Notice that a new line is not started until you use
, rather than
. Also
println
print
notice that the new line starts
after
outputting the items specified in the
. This
println
is the only difference between
and
.
print
println
versus
println
print
The only difference between
and
is that with
System.out.println
System.out.print
println , the next output goes on a new line , whereas with print , the next output is
placed on the same line .
EXAMPLE
System.out.print("Tom ");
System.out.print("Dick ");
System.out.println("and ");
System.out.print("Harry ");
produces the following output:
Tom Dick and
Harry
(The output would look the same whether the last line read print or println .)
Another way to describe the difference between
and
is to note that
print
println
System.out.println(
SomeThing
);
is equivalent to
System.out.print(
SomeThing
+ "\n");
Search WWH ::




Custom Search