Exercises

  1. Can you read the code in this program and guess what the output is (without running it in Kotlin Playground)?
fun main() {
    println
("1")
    println
("2")
    println
("3")
}

Once you have a guess, copy and paste this code into the Kotlin Playground to check your answer.

  1. Use the Kotlin Playground to create a program that outputs the following messages:
  1. Copy and paste this program into the Kotlin Playground.
fun main{(I'm
learning
Kotlin!WALLALL Knowledge Base)
{
    println
("WALLALL")
    println
("WALLALL Knowledge Base")
    println("WALLALL
")
    println
("WALLALL")
    println
("WALLALL Knowledge Base")
}

Fix the program so that it prints this output:

WALLALL
WALLALL Knowledge Base
WALLALL
WALLALL
WALLALL Knowledge Base

For some early practice on troubleshooting, fix the errors in the following exercises. For each exercise, copy the code into the Kotlin Playground in your browser. Try to run the program and you'll see an error message appear.

  1. Fix the error in this program, so that it produces the desired output.
fun main() {
    println
("I'm learning Kotlin!WALLALL Knowledge Base
")

Desired output:

WALLALL Knowledge
  1. Fix the error in this program, so that it produces the desired output.
fun main() {
    printLine
("There is a chance of snow")
}

Desired output:

There is a chance of snow
  1. Fix the error in this program, so that it produces the desired output.
fun main() {
    println
("Cloudy") println("Partly Cloudy") println("Windy")
}

Desired output:

Cloudy
Partly Cloudy
Windy
  1. Fix the error in this program, so that it produces the desired output.
fun main() (
    println
("How's the weather today?")
)

Desired output:

How's the weather today?

After you complete these exercises, check your answers against the solutions in the next section.

Back
Next

Comments

Popular

Section id