Kotlin Output

Kotlin Output (Print Text)

In Kotlin, text or output is printed to the console using print() and println() functions.


1. println() – Print with New Line

println() prints the text and moves the cursor to the next line.

fun main() {
println("Hello Kotlin")
println("Welcome to Programming")
}

Output:

Hello Kotlin
Welcome to Programming

2. print() – Print without New Line

print() prints text without moving to a new line.

fun main() {
print("Hello ")
print("Kotlin")
}

Output:

Hello Kotlin

3. Printing Variables

fun main() {
val name = "Sanjit"
val age = 22
println(name)
println(age)
}


4. String Templates (Recommended Way)

Use $ to print variables inside strings.

fun main() {
val language = "Kotlin"
val version = 1.9
println(“Language: $language“)
println(“Version: $version“)
}


5. Printing Expressions

Use ${} to print expressions.

fun main() {
val a = 10
val b = 20
println(“Sum = ${a + b}“)
}


6. Printing Multiple Values

fun main() {
val x = 5
val y = 10
println(“x = $x, y = $y“)
}


7. Escape Characters in Output

fun main() {
println("Hello\nKotlin") // New line
println("Hello\tKotlin") // Tab space
println("She said \"Hi\"") // Double quotes
}

8. Printing Without Quotes (Numbers & Boolean)

fun main() {
println(100)
println(true)
println(45.6)
}

Summary

  • print() → prints text on same line

  • println() → prints text on new line

  • $variable → print variable value

  • ${expression} → print expressions

You may also like...