Q:

Kotlin program to find largest of three numbers

belongs to collection: Kotlin Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to swap two numbers... >>
<< Kotlin program to input a string...