Printing text
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')
108cQ3
22E81