← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 7 of 8

println and print

println shows something on the screen and moves to the next line, while print stays on the same line. It is like speaking a sentence and either pressing enter or continuing on.

In this page:

  1. println and print
Syntax
scala
println(value)
print(value)

println and print

println prints a value followed by a newline, while print prints without adding one. Both accept any value and call .toString on it implicitly.

println is by far the more commonly used of the two, since most output benefits from ending on its own line.

Note: Use string interpolation (s"...") with println for the clearest, most readable way to build formatted output.

Example: println and print

markup
object Main extends App {
  println("This line ends with a newline")
  print("This line ")
  print("does not, so ")
  println("this continues on the same line")
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using print and getting all the output on one line because it does not add a newline.
  2. Passing several values like println("a", "b"), which prints a tuple (a,b) instead of two values.
  3. Expecting println to format numbers, such as println(3.10) printing 3.1, when you need f"..." for fixed decimals.
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.