Q:

Kotlin program to get system name

belongs to collection: Kotlin system programs

0

The task is to get the system name.

All Answers

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

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

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

total answers (1)

Kotlin program to get CPU serial number of Windows... >>
<< Kotlin program to get system motherboard serial nu...