Kotlin Variables Example
Chapter:
Kotlin
Last Updated:
11-11-2017 18:12:26 UTC
Program:
/* ............... START ............... */
fun main(args : Array<String>) {
var name = "Kotlin"
val cash = 95
var percentage = 10.34
println(name+"-"+cash+"-"+percentage)
var language: String // String Variable Declaration
language = "english" // Initializing the variaable
val score: Int // Int variable Declaration
score = 200 // Initializing the variaable
}
/* ............... END ............... */
Output
Notes:
-
In Kotlin either var or val keyword is used to declare the variable.
- We don't want to specify the type of variable, Kotlin implicitly conveting to the proper data types.
- val in Kotlin : The variable declared using val keyword cannot be changed once the value is assigned.
- It is similar to final variable in Java.
- var in Kotlin - The variable declared using var keyword can be changed later in the program. It corresponds to regular Java variable.
- Go through the above program to get more understanding about Kotlin var and val.
Tags
Variables Example , Kotlin, var, val