You are developing a Kotlin program to calculate the division of two numbers. Normally, your values work fine, but in the new version of your program, a user has directly inputted the values, which can sometimes include a zero as the divisor. Make sure to devise your program such that in case a user tries to divide by zero, an exception is caught and a message 'Can't divide by zero!' is printed instead of letting the program crash. For this, fill the blanks in the code provided to you.
Errors in programs
Handling division by zero in a calculator program
Report a typo
Fill in the gaps with the relevant elements
fun main() {
{
val num = 100
val divisor = 0
val result = num / divisor
} (e: ) {
println("Can't divide by zero!")
}
} ___
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.