There are three kinds of print statements:
System.out.print(argument)just prints out its argument, and
System.out.println(argument)prints out its argument and ends the line.
A third kind,
gives more control over how things are printed.
Example Result System.out.print("one"); System.out.print("two"); System.out.println("three"); onetwothree System.out.println("one"); System.out.println("two"); System.out.println("three"); one two three
A print "statement" is actually a call to the
println method of the
println method takes one argument or no arguments.
However, the one argument may be a
String which you create using
the string concatenation operator
+. If you ask to print an
println methods call that object's
to get a printable string.
Example Result int x = 3; int y = 5; System.out.println(x + " and " + y + " is " + (x + y)); 3 and 5 is 8 int x = 3; int y = 5; System.out.println(x + " and " + y + " is " + x + y); 3 and 5 is 35
Anything concatenated ("added") to a string is first converted to a string
itself. In the second example above, the
x is concatenated with the string,
y is concatenated.