Home »
Kotlin »
Kotlin Programs »
Kotlin Basic Programs
Kotlin program to find largest of three numbers
Kotlin | Largest of three numbers: Here, we are going to learn how to find the largest number from given 3 numbers in Kotlin programming language?
Submitted by IncludeHelp, on April 20, 2020
Problem statement
Input 3 integer numbers, we have to find the largest of these input numbers.
Example:
Input:
First number: 10
Second number: 20
Third number: 30
Output:
Largest number: 30
Program to find largest of three numbers in Kotlin
package com.includehelp.basic
import java.util.*
// Main Method Entry Point of Program
fun main(args: Array<String>) {
// InputStream to get Input
val reader = Scanner(System.`in`)
// Input Integer values
println("Enter First Value : ")
var first = reader.nextInt()
println("Enter Second Value : ")
var second = reader.nextInt()
println("Enter Third Value : ")
var third = reader.nextInt();
// condition to find largest of three numbers
val largest = if(first>second && first>third)
first
else if(second>third)
second
else
third
println("Largest Number is: $largest")
}
Output
Enter First Value :
23
Enter Second Value :
45
Enter Third Value :
89
Largest Number is: 89