Your friends asked for your help in solving a coding problem. They were trying to create a utility method for swapping two integer numbers, but something went wrong and the method does not work as expected. Use your debugging skills to fix the problem.
Debugging techniques
Find the error
Report a typo
Sample Input 1:
29
-16Sample Output 1:
-16
29Write a program in Kotlin
import java.util.Scanner
fun swapInts(ints: IntArray): IntArray {
return intArrayOf(ints[1], ints[0])
}
fun main() {
val scanner = Scanner(System.`in`)
while (scanner.hasNextLine()) {
var ints = intArrayOf(
scanner.nextLine().toInt(),
scanner.nextLine().toInt(),
)
swapInts(ints)
println(ints[0])
println(ints[1])
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.