Swap

Report a typo

Suppose you have two variables a and b that store some numbers. Swap the values of these variables. For example, if a = 3 and b = 5, then after running the code, a will contain 5, and b will contain 3.

Try to do it with the help of a third variable c. You can imagine that variables are just boxes with values, and you need to swap their contents, like this:

Example of replacing values of two variables with a third variable.

Write a program in Kotlin
fun main() {
// Don't be afraid of the code below!
// In the future, you will definitely cope with it, but for now just ignore it.
var (a, b) = readLine()!!.split(" ").map { it.toInt() }

// Write only exchange actions here. Do not touch the lines above
val c =


// Do not touch the lines below
print("$a $b")
}

Create a free account to access the full topic