Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
No Result
View All Result
Home Kotlin

Kotlin Syntax & Output (Print Text) (Lesson 2 PDF)

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
Kotlin Syntax & Output (Print Text) (Lesson 2 PDF)

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains and is now an official language for Android development. Kotlin is designed to be concise, expressive, and safe. It is also interoperable with Java, which means that you can use Kotlin and Java code together in the same project.

Kotlin

You might also like

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin Functions & Classes (Lesson 11 PDF)

Kotlin Syntax & Output (Print Text) (Lesson 2 PDF)

Overview about the Lesson

In this lesson, you will learn about printing text in Kotlin. You will learn how to use the println() and print() functions to output values and print text. You will also learn how to format strings using string templates.

Kotlin Syntax & Output (Print Text) (Lesson 2 PDF) – page 2
Kotlin Syntax & Output (Print Text) (Lesson 2 PDF) – page 3

The Content of the Lesson

The lesson is divided into two parts. In the first part, you will learn how to use the println() and print() functions to output values and print text. You will also learn how to format strings using string templates. In the second part, you will learn how to use the readLine() function to read input from the user.

Why This Lesson

This lesson is designed for programmers who are new to Kotlin and want to learn how to print text and read input from the user. It is also suitable for programmers who are familiar with Java and want to learn Kotlin.

Kotlin Output in Practice: println, print and String Templates

This lesson’s PDF covers Kotlin’s syntax rules and how to print text. Here is a hands-on summary with runnable examples.

println() vs print()

fun main() {
    print("Hello ")
    print("World")
    println()          // just moves to a new line
    println("Line 1")
    println("Line 2")
}

Output:

Hello World
Line 1
Line 2

print() keeps the cursor on the same line; println() adds a line break after the text.

Printing numbers and calculations

fun main() {
    println(42)
    println(3 + 4 * 2)   // 11, multiplication first
    println(10 / 4)      // 2, whole-number division
    println(10.0 / 4)    // 2.5
}

Note that dividing two whole numbers gives a whole number. Use a decimal (10.0) to get a decimal result.

String templates: mixing text and values

fun main() {
    val item = "Laptop"
    val price = 950
    println("The $item costs $price dollars")
    println("Two of them cost ${price * 2}")
}

Use $variable for a simple variable and ${expression} for any calculation or property, such as ${item.length}.

Special characters

EscapeMeaningExample output
nNew lineSplits text over two lines
tTabAdds horizontal space
“Double quotePrints a quote inside a string
\BackslashPrints a single
$Dollar signPrints $ instead of starting a template

Multi-line strings

fun main() {
    val menu = """
        1. New game
        2. Load game
        3. Exit
    """.trimIndent()
    println(menu)
}

Triple-quoted strings keep line breaks exactly as typed, and trimIndent() removes the common leading spaces.

Kotlin syntax rules to remember

  • Every program starts in fun main().
  • Semicolons are optional; one statement per line is the norm.
  • Kotlin is case-sensitive: println works, PrintLn does not.
  • Code blocks use curly braces { }; indentation is for readability only.

Practice exercise

Print a small receipt with an item name, a quantity of 3 and a unit price of 12.5, and calculate the total with a string template.

fun main() {
    val item = "Notebook"
    val qty = 3
    val unitPrice = 12.5
    println("Item: $item")
    println("Total: ${qty * unitPrice}")   // Total: 37.5
}

Frequently Asked Questions

How do I print a dollar sign in Kotlin?

Escape it with a backslash: println("Price: $5"). A $ not followed by a valid identifier also prints as is.

Can I format numbers to two decimal places?

Yes: println("%.2f".format(37.456)) prints 37.46.

Continue the course

← Previous: Lesson 1: Getting Started  |  Next: Lesson 3: Comments & Variables →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output (you are here)
  3. Lesson 3: Comments & Variables
  4. Lesson 4: Data Types
  5. Lesson 5: Operators
  6. Lesson 6: Set Operations & Grouping
  7. Lesson 7: Booleans & If…Else
  8. Lesson 8: When, While, Break & Continue
  9. Lesson 9: Arrays
  10. Lesson 10: For Loops & Ranges
  11. Lesson 11: Functions & Classes
  12. Lesson 12: Classes, Objects & Constructors
  13. Lesson 13: Class Functions & Inheritance

Conclusion

Printing text and reading input are essential skills for any programmer. In this lesson, you learned how to use the println() and print() functions to output values and print text. You also learned how to format strings using string templates and how to read input from the user using the readLine() function.

Download From Link

You can download the lesson from the following link:

From Here

Tags: AndroidJavaKotlinProgramming
Previous Post

Kotlin Getting Starting From Scratch (Lesson 1 PDF)

Next Post

 Kotlin Comments & Variables (Lesson 3 PDF) 

Ahmed Elhozayen

Ahmed Elhozayen

Ahmed Elhozayen writes and curates the guides on Connect4Techs Tech. He works in the IT field and focuses on practical, step-by-step resources for Excel, data analysis, finance, MBA studies and Kotlin programming, so readers can apply what they learn the same day.

Related Posts

Kotlin Class Functions & Inheritance (Lesson 13 PDF)
Kotlin

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)
Kotlin

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Functions & Classes (Lesson 11 PDF)
Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)
Kotlin

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

by Ahmed Elhozayen
October 11, 2026
 Kotlin Arrays (Lesson 9 PDF)
Kotlin

 Kotlin Arrays (Lesson 9 PDF)

by Ahmed Elhozayen
October 11, 2026
Next Post
 Kotlin Comments & Variables (Lesson 3 PDF) 

 Kotlin Comments & Variables (Lesson 3 PDF) 

Recommended

Top Excel Formulas for Finance Grads PDF

Top Excel Formulas for Finance Grads PDF

October 11, 2026
Excel Keyboard Shortcuts for Window Users (PDF)

Excel Keyboard Shortcuts for Window Users (PDF)

October 11, 2026

Categories

  • apple
  • Canon
  • Data Analysis
  • Excel
  • Finance
  • ios
  • Kotlin
  • Marketing
  • MBA
  • Samsung
  • Software Tutorials
  • Technology

Don't miss it

20 Essential Excel Formulas Every Data Analyst Must Know in 2026
Data Analysis

20 Essential Excel Formulas Every Data Analyst Must Know in 2026

May 18, 2026
Excel guide for data analytics learners
Excel

Excel for Data Analysis PDF

October 11, 2026
The Ultimate Guide to Financial Modeling PDF
Excel

The Ultimate Guide to Financial Modeling PDF

October 11, 2026
The Ultimate Excel Handbook PDF
Excel

The Ultimate Excel Handbook PDF

October 11, 2026
𝟓𝟎 𝐄𝐱𝐜𝐞𝐥 𝐒𝐡𝐨𝐫𝐭𝐜𝐮𝐭 𝐊𝐞𝐲
Excel

50 Excel Shortcut Key PDF: Streamline Your Workflow

March 21, 2025
Most Useful Excel Keyboard Shortcuts For Windows and Mac OS
Excel

Most Useful Excel Keyboard Shortcuts for Windows and Mac OS PDF

March 21, 2025
Connect4Techs Tech

Practical, free guides on Excel, data analysis, finance, business and programming — written to help you learn faster and work smarter.

Follow on Facebook

Topics

  • Excel
  • Kotlin
  • MBA
  • Finance
  • Data Analysis
  • Apple
  • Technology
  • Software Tutorials

Latest articles

  • 20 Essential Excel Formulas Every Data Analyst Must Know in 2026May 18, 2026
  • Excel for Data Analysis PDFAug 31, 2025
  • The Ultimate Guide to Financial Modeling PDFApr 19, 2025

Company

  • About us
  • Contact
  • Privacy Policy
  • Terms of Use
  • IT Certification PDFs
  • AI Tools & News (Connect4AI)
© 2026 Connect4Techs. All rights reserved. Privacy · Terms · Contact
No Result
View All Result
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact