Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 有没有办法在Kotlin中获取列表的用户输入?_List_Kotlin_User Input - Fatal编程技术网

List 有没有办法在Kotlin中获取列表的用户输入?

List 有没有办法在Kotlin中获取列表的用户输入?,list,kotlin,user-input,List,Kotlin,User Input,我想让用户输入一些值,而不是声明一些默认值。请帮助我更改第二行代码 //Program To Print The Product of List using Extension function. fun main(){ var list = listOf(1,2,3,4,5,6) println("The product of $list is ${list.product()} ") } fun List<Int>.product():Int

我想让用户输入一些值,而不是声明一些默认值。请帮助我更改第二行代码

//Program To Print The Product of List using Extension function.
fun main(){
    var list = listOf(1,2,3,4,5,6)
    println("The product of $list is ${list.product()} ")
}

fun List<Int>.product():Int{
    var sum = 1
    for(i in this){
        sum *= i
    }
    return sum
}
//使用扩展函数打印列表产品的程序。
主要内容(){
var列表=列表(1,2,3,4,5,6)
println(“$list的乘积是${list.product()}”)
}
fun List.product():Int{
var总和=1
因为(我在这里){
总和*=i
}
回报金额
}
您可以使用
readLine()。如果您想逐行输入
List(size){readLine()!!}
应该可以(您也可以使用
readLine
读取大小,由您决定),如果您在一行中输入所有数字,并以空格分隔(动态大小),
readLine()!!。split(“”).map{it.toInt()}
应该这样做。