【发布时间】:2021-05-12 21:42:06
【问题描述】:
我正在尝试遵循“Head First Kotlin”书籍练习,并编写了以下代码:
val numList = arrayOf(1,2,3);
var x = 0;
fun main() {
while (x < 3) {
println("Item $x is $numList[x]");
x += 1;
}
}
Kotlin 打印:
Item 0 is [Ljava.lang.Integer;@30f39991[x]
Item 1 is [Ljava.lang.Integer;@30f39991[x]
Item 2 is [Ljava.lang.Integer;@30f39991[x]
但我希望是:
Item 0 is 1
Item 1 is 2
Item 3 is 3
我做错了什么? 任何帮助将不胜感激!
【问题讨论】:
-
仅供参考,Kotlin 中的 semicolons
;are not needed。它们在大多数情况下都是推断出来的,但链接的答案中列出了例外情况。
标签: kotlin