ADVERTISEMENT
ADVERTISEMENT

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
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.