kotlin 字符串
To input a string in Kotlin, we use the "readLine()" method.
要在Kotlin中输入字符串,我们使用“ readLine()”方法。
In the below program, we will input a string from the user and print it on the screen.
在下面的程序中,我们将输入用户的字符串并将其打印在屏幕上 。
在Kotlin中输入字符串的程序 (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.
在上述程序中,我们要求输入名称,地址和国家/地区的值。 这三个值都是字符串,并且它们通过readLine()方法读取。
kotlin 字符串