Cookie Preferences

We use cookies to enhance your experience. Choose your preference for cookie usage.

Essential cookies are required for basic functionality. Additional cookies help us improve our service and provide analytics.

View third-party services
  • Google Analytics: Website traffic analysis and conversion tracking
  • RudderStack: Analysis of user interactions with the website
  • Microsoft Clarity: User behavior analysis & session recordings
  • Facebook Pixel: Marketing analysis of user activity
KotlinStandard input and output

Standard output

3 seconds read
Standard output is a place to which a program can send information (text). It is supported by all common operating systems. Not all programs generate such output. By default, the standard output displays data on the screen, but it is possible to redirect it to a file.

Throughout this course, you will often write programs which send some data (e.g. strings and numbers) to the standard output.

Printing text

Kotlin has two useful functions to send data to the standard output. The functions are called println and print.

The function println (print line) displays the passed string followed by a new line on the screen. For example, the following code fragment prints four lines:

println("I")
println("know")
println("Kotlin")
println("well.")
Output:
I
know
Kotlin
well.

Note that all the strings were printed as-is, without the double quotes.

This function allows you to print an empty line when no string is given:

println("Kotlin is a modern programming language.")
println() // prints an empty line
println("It is used all over the world!")

Output:

Kotlin is a modern programming language.

It is used all over the world!

The function print displays the passed value and places the cursor (the place where to print) after it. As an example, the code below outputs all strings in a single line.

print("I ")
print("know ")
print("Kotlin ")
print("well.")

Output:

I know Kotlin well.

Printing numbers and characters

The functions println and print allow a program to print not only strings, but also numbers as well as characters.

Let's print two secret codes.

print(108)   // prints a number
print('c')   // prints a character
print("Q")   // prints a string
println('3') // prints a character that represents a digit 

print(22)
print('E')
print(8)
println('1')
Output:
108cQ3
22E81
Note that in the output none of the characters contain quotes.
How did you like the theory?
Report a typo