To find the maximum of two numbers in Kotlin, you can use the coerceAtLeast
function.
In this example,
a
and b
and assign values to them.coerceAtLeast
function to find the maximum of a
and b
and store it in a variable named max
.println
.fun main() {
val a = 10
val b = 15
val max = a.coerceAtLeast(b)
println("Maximum of $a and $b is: $max")
}
Maximum of 10 and 15 is: 15
In this tutorial, we learned How to find the Maximum of Two Numbers in Kotlin language with well detailed examples.