Kotlin输出HelloWorld

Posted on Jan 18, 2025

以下是Kotlin输出"Hello, world!"的简单代码:

package top.blackcyan.kt

fun main() {
	println("Hello, world!")
}

或者说,你想使用一些花里胡哨的方法:

package top.blackcyan.kt

val message: ListOf<String> = ["Hello ", "world!"]
message.forEach { 
	print(it)
}
println()

也有更加花里胡哨的办法,请不要在真正的项目中这么做,会被骂()

package top.blackcyan.kt

fun greeting() = "Hello"
fun String.printOut() { println("${greeting()} $this!") }
fun main() {
	"world".printOut()
}