SDSnipDojo
← All lessons
Lesson 01 / 124 steps2 exercises

Hello, Kotlin

Print to the console and embed values in strings.

1. println — printing output

Every Kotlin program starts in a function called main. The println function writes a single line to standard output:

fun main() {
    println("Hello, world!")
}

You can call it as many times as you like — each call produces its own line:

fun main() {
    println("Line 1")
    println("Line 2")
}

Strings sit between double quotes "...".

2. Print a message

Change the body of message() so it returns the string Hello, SnipDojo! — exactly. The harness will print and check it.

Starter code

fun message(): String {
    return "Hello"
}

3. String templates

Embed values inside a string with $variable (single value) or ${expression} (any expression):

val name = "Ada"
println("Hello, $name!")            // Hello, Ada!

val a = 3
val b = 4
println("Sum is ${a + b}")         // Sum is 7

This is the idiomatic way to build strings in Kotlin — much nicer than concatenating with +.

4. Greet with templates

Implement greet(name) so greet("Ada") returns "Hi, Ada!". Use a string template — return "Hi, $name!".

Starter code

fun greet(name: String): String {
    return "Hi"
}

Run this Kotlin lesson in your browser

SnipDojo ships an in-browser Kotlin editor with the exercises above already wired to tests. Sign in with Google to edit the starter code, run it, and track your progress toward the free certificate — no installs and no local toolchain.

Sign in to run this code →