Kotlin Program to Find the Largest Among Three Numbers: In this Kotlin programming, we will learn how to find out the largest number among the three. The user will enter the number values, our program will find and print out the result. To compare three numbers and finding out the largest one, we can either implement our own algorithm or we can use Kotlin’s built-in method maxOf.
Kotlin program to find out the largest among three numbers
Source Code
fun main(args: Array<String>) {
val n1 = -4.5
val n2 = 3.9
val n3 = 2.5
if (n1 >= n2 && n1 >= n3)
println("$n1 is the largest number.")
else if (n2 >= n1 && n2 >= n3)
println("$n2 is the largest number.")
else
println("$n3 is the largest number.")
}
Output
Kotlin program to find out the largest among three numbers