Avoid division by zero

Report a typo

Here is a program that reads numbers and performs some calculations. It outputs the result to the standard output.

In some cases, the program will throw an ArithmeticException. Fix the program so that it prints "Division by zero!" instead of this exception.

Sample Input 1:

5
2
0
1

Sample Output 1:

2
Write a program in Kotlin
fun main() {
val a: Int = readln().toInt()
val b: Int = readln().toInt()
val c: Int = readln().toInt()
val d: Int = readln().toInt()

val result = a / ((b + c) / d)

println(result)
}

Create a free account to access the full topic