Example: #1 - Swapping of two numbers using temporary variable
Kotlin Input Screen
fun main(args: Array<String>) {
var a: Int = 3
var b: Int = 6
println("The value of a before swap is $a")
println("The value of b before swap is $b")
// Swapping of two numbers using temp variable
val temp: Int = a
a = b
b = temp
println("The value of a after swap is $a")
println("The value of b after swap is $b")
}
Kotlin Output Screen
The value of a before swap is 3
The value of b before swap is 6
The value of a after swap is 6
The value of b after swap is 3