Kotlin Output

Kotlin Output (Print Text)

To output text or variables in Kotlin, you primarily use two built-in functions: println() and print().


1. The println() Function

The println() function prints the text inside the parentheses, and then automatically adds a new line at the end. The next output will start on a new line.

Example

fun main() {
  println("Hello World!")
  println("I am learning Kotlin.")
  println("It is awesome!")
}

You can add as many println() functions as you want. Each will output on a new line.


2. The print() Function

The print() function is similar to println(), but it does not insert a new line at the end of the output.

Example

fun main() {
  print("Hello World! ")
  print("I will print on the same line.")
}

Outputting Numbers

You can also use println() to output numbers and perform mathematical calculations directly inside the parentheses without using quotes.