Kotlin program to get system name

Kotlin | Getting system name: Here, we are going to learn how to get the system name in Kotlin programming language?
Submitted by IncludeHelp, on May 05, 2020

The task is to get the system name.

package com.includehelp

import java.net.InetAddress


/**
 * Function for System Name
 */
fun getSystemName(): String? {
    return try {
        InetAddress.getLocalHost().hostName
    } catch (E: Exception) {
        System.err.println("System Name Exp : " + E.message)
        null
    }
}

//Main function , Program Entry Point
fun main(args: Array<String>) {

    // Call Function to get Computer System Name
    val systemName = getSystemName()

    // Print Computer Name
    println("Computer Name : $systemName")
}

Output

Computer Name : DESKTOP-16EO58R


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.