July 2018
Intermediate to advanced
400 pages
12h 14m
English
Imagine you are writing an adventure game that allows a player to explore an interactive world. You may want a variable for keeping track of the player’s score.
In TypeIntro.kt, create your first variable, called experiencePoints, and assign it a value:
Listing 2.2 Declaring an experiencePoints variable (TypeIntro.kt)
fun main(args: Array<String>) {
var experiencePoints: Int = 5
println(experiencePoints)
}
Here, you have assigned an instance of the type Int to a variable called experiencePoints. Let’s walk through each part of what happened.
You defined a variable using the keyword var, which indicates that you want to declare a new variable, followed by the new variable’s name.
Next, you specified ...
Read now
Unlock full access