Kotlin 输出 HelloWorld

95 字
1 分钟
Kotlin 输出 HelloWorld

以下是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()
}

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Kotlin 输出 HelloWorld
https://blog.blackcyan.top/posts/kotlin-hello-world/
作者
墨青BlackCyan
发布于
2025-01-18
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
墨青BlackCyan
三点几了,饮茶先啦
公告
欢迎来到墨青的博客!
音乐
封面

音乐

暂未播放

0:000:00
暂无歌词
分类
标签
站点统计
文章
12
分类
2
标签
25
总字数
7,351
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.13.10
文章许可
CC BY-NC-SA 4.0

当前页面没有目录