ADVERTISEMENT
ADVERTISEMENT

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

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.