• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

system.out.print vs println

 
Brandi Love
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between the print and println commands?
 
S. Stacey
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println will print on a new line where System.out.print will print and the same line.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println will print on a new line where System.out.print will print and the same line.

Println() won't print on a new line, it will terminate the current line with a newline character or sequence. In other words, println() will print an end-of-line character, while print() will not. If you invoke println() after a print(), the argument to println() will append to the argument to print(). Here's an example:

Running this snippet in a program produces Jeff Bosch on one line, then places the cursor at the beginning of the next line.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic