ADVERTISEMENT
ADVERTISEMENT

Home » Kotlin » Kotlin programs » Kotlin basic programs

Kotlin program to input a string

Kotlin | Input String: Here, we are going to learn how to input/read and print a string in Kotlin programming language?
Submitted by IncludeHelp, on April 16, 2020

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.

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.

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.