Q:

Kotlin program to input a string

belongs to collection: Kotlin Basic Programs

0

To input a string in Kotlin, we use the "readLine()" method.

In the below program, we will input a string from the user and print it on the screen.

All Answers

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

Program to input a string in Kotlin

package com.includehelp.basic

// Main Method Entry Point of Program
fun main(args: Array<String>) {
    
    // Input name
    println("Enter Your Name: ")
    val name = readLine()
    
    // Input Address
    println("Enter Your Address: ")
    val add = readLine()
    
    // Input Country Name
    println("Enter Your Country Name : ")   
    val country = readLine()
    
    // Printing input values
    println("Name: $name")
    println("Address: $add")
    println("County: $country")
}

Output

Enter Your Name: 
Shivang
Enter Your Address: 
Indore, sector 73
Enter Your Country Name : 
India
Name: Shivang
Address: Indore, sector 73
County: India

In the above program, we are asking the values for name, address and country. All three values are strings and they are reading by readLine() method.

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 find largest of three numbers... >>
<< Kotlin program to input numbers (integer, float, d...