Variable Declaration in Kotlin

Level 258 keystrokes

Declares a read-only variable with val and a mutable one with var, then prints both with a string template.

Kotlin code

// val declares a variable that cannot be reassigned
1val name = "Kotlin"
// var declares a variable that can be reassigned later
2var count = 0
// $name and $count insert the values: prints "Kotlin: 0"
3println("$name: $count")

Output

Kotlin: 0
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Kotlin code and how often they appear.

  • "× 4
  • =× 2
  • $× 2
  • :× 1
  • (× 1
  • )× 1

More Kotlin examples at level 2

← Kotlin typing practice