kotlin 字符串_Kotlin程序输入字符串

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()方法读取。

翻译自: https://www.includehelp.com/kotlin/input-a-string.aspx

kotlin 字符串

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值