0
0
Kotlinprogramming~5 mins

Print and println output in Kotlin

Choose your learning style9 modes available
Introduction

We use print and println to show messages or results on the screen. This helps us see what our program is doing.

To show a greeting message to the user.
To display the result of a calculation.
To debug by checking values of variables.
To ask the user for input by showing a prompt.
To print multiple lines of information step by step.
Syntax
Kotlin
print("message")
println("message")

print shows the message but stays on the same line.

println shows the message and moves to the next line.

Examples
This prints Hello World on the same line.
Kotlin
print("Hello")
print(" World")
This prints Hello and then World on the next line.
Kotlin
println("Hello")
println("World")
Using \n inside print moves to a new line manually.
Kotlin
print("Hello\n")
print("World")
Sample Program

This program shows how print and println work together to print text on the screen.

Kotlin
fun main() {
    print("Hello")
    print(" ")
    println("World")
    println("Welcome to Kotlin!")
}
OutputSuccess
Important Notes

Remember, println always adds a new line after printing.

You can use print multiple times to build a line before moving to the next.

Summary

print shows text without moving to a new line.

println shows text and moves to the next line.

Use them to display messages and results clearly.